如何在fyne中使用滚动容器内的列表小部件?

huangapple go评论139阅读模式
英文:

How to use List widget inside scroll container in fyne?

问题

每当我在滚动容器中使用列表小部件时,滚动条就会折叠,但如果我使用标签小部件,那么滚动容器就是全宽度全高度的,但是当我使用列表小部件时,它就会折叠。

不起作用(滚动条折叠)

func ShowListDialog(win fyne.Window, messages []string){
	list := widget.NewList(
		func() int {
			return len(messages)
		},
		func() fyne.CanvasObject {
			return widget.NewLabel("label")
		},
		func(i widget.ListItemID, o fyne.CanvasObject) {
			o.(*widget.Label).SetText(messages[i])
		},
	)
	d := dialog.NewCustom("Messages", "Close" , container.NewScroll(list), win) 
	d.Resize(fyne.NewSize(500, 400))
	d.Show()
}

对于标签有效(滚动条具有全宽度和高度)

func ShowLabelDialog(win fyne.Window, message string){
	d := dialog.NewCustom("Message", "Close", container.NewScroll(widget.NewLabel(message)), win) 
	d.Resize(fyne.NewSize(500, 400))
	d.Show()
}
英文:

Scroll collapses everytime i use list widget inside scroll container, if i use label widget then scroll container is full width and full height but when i use list widget it just collapses.

Not Working (Scroll collapses)

func ShowListDialog(win fyne.Window, messages []string){
	list := widget.NewList(
		func() int {
			return len(messages)
		},
		func() fyne.CanvasObject {
			return widget.NewLabel("label")
		},
		func(i widget.ListItemID, o fyne.CanvasObject) {
			o.(*widget.Label).SetText(messages[i])
		},
	)
	d := dialog.NewCustom("Messages", "Close" , container.NewScroll(list), win) 
	d.Resize(fyne.NewSize(500, 400))
	d.Show()
}

Working for label (scroll has full width&height)

func ShowLabelDialog(win fyne.Window, message string){
	d := dialog.NewCustom("Message", "Close", container.NewScroll(widget.NewLabel(message)), win) 
	d.Resize(fyne.NewSize(500, 400))
	d.Show()
}

答案1

得分: 1

列表小部件已经包含了一个滚动条 - 移除外部的滚动条应该可以解决你的问题。

英文:

The list widget already contains a scroll - removing the outer one should resolve your issue.

huangapple
  • 本文由 发表于 2022年4月5日 02:17:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/71741966.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定