我正在尝试使用Fyne(https://fyne.io/)设置应用布局,但遇到了一些问题;这是我的代码:
func main() {
myApp := app.New()
myWindow := myApp.NewWindow("Demo")
myWindow.SetMaster()
myWindow.SetPadded(false)
myWindow.Resize(fyne.NewSize(1024, 600))
//myWindow.SetFullScreen(true)
r1 := canvas.NewRectangle(color.RGBA{255, 0, 0, 255})
r1.SetMinSize(fyne.NewSize(1024, 110))
top := fyne.NewContainerWithLayout(layout.NewMaxLayout(), r1)
r2 := canvas.NewRectangle(color.RGBA{0, 255, 0, 255})
r2.SetMinSize(fyne.NewSize(1024, 400))
middle := fyne.NewContainerWithLayout(layout.NewMaxLayout(), r2)
message := widget.NewLabel("message")
messageWrap := fyne.NewContainerWithLayout(layout.NewCenterLayout(), message)
middle.AddObject(messageWrap)
r3 := canvas.NewRectangle(color.RGBA{255, 0, 255, 255})
r3.SetMinSize(fyne.NewSize(1024, 55))
bottom := fyne.NewContainerWithLayout(layout.NewMaxLayout(), r3)
data := widget.NewLabel("data")
dataWrap := fyne.NewContainerWithLayout(layout.NewCenterLayout(), data)
ua := widget.NewLabel("ua")
uaWrap := fyne.NewContainerWithLayout(layout.NewCenterLayout(), ua)
bottomWrap := fyne.NewContainerWithLayout(layout.NewBorderLayout(nil, nil, dataWrap, uaWrap), dataWrap, uaWrap)
bottom.AddObject(bottomWrap)
content := fyne.NewContainerWithLayout(layout.NewBorderLayout(top, bottom, nil, nil), top, bottom, middle)
myWindow.SetContent(content)
myWindow.ShowAndRun()
}
这是输出:
我是这个图书馆的新手,我很难理解它的工作原理。我需要删除布局中top
,middle
和bottom
块之间的“填充”;有办法吗?
答案 0 :(得分:3)
您正在使用BorderLayout,此布局(与大多数内置布局一样)在元素之间添加了填充,没有布局配置可将其关闭。
您有两个选择:
传入您自己的布局,该布局可以完全根据您的意愿移动和调整元素大小
设置一个自定义主题,其中填充设置为0(不建议使用)。
您会发现该库对小部件和布局的工作方式持保留态度。它强加的一件事是,每个标准布局都将每个元素都用填充分隔。