像这样?或者描述更多细节。
package main
import (
"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/layout"
"fyne.io/fyne/widget"
)
func main() {
f := app.New()
w := f.NewWindow("")
label1 := widget.NewLabel("Label1")
b1 := widget.NewButton("Button1", func() {})
b2 := widget.NewButton("Button2", func() {})
label2 := widget.NewLabel("Label3")
w.SetContent(
fyne.NewContainerWithLayout(
layout.NewVBoxLayout(),
fyne.NewContainerWithLayout(layout.NewHBoxLayout(), layout.NewSpacer(), label1, layout.NewSpacer()),
layout.NewSpacer(),
fyne.NewContainerWithLayout(layout.NewHBoxLayout(), layout.NewSpacer(), b1, b2, layout.NewSpacer()),
layout.NewSpacer(),
fyne.NewContainerWithLayout(layout.NewHBoxLayout(), layout.NewSpacer(), label2, layout.NewSpacer()),
),
)
w.Resize(fyne.Size{Height: 320, Width: 480})
w.ShowAndRun()
}
编辑:试过NewBorderLayout
但不确定这是否是你想要的。
拿到的时候别忘了告诉我正确的方法。祝你好运!
package main
import (
"fmt"
"fyne.io/fyne"
"fyne.io/fyne/app"
"fyne.io/fyne/layout"
"fyne.io/fyne/widget"
)
func main() {
f := app.New()
w := f.NewWindow("")
label1 := widget.NewLabel("Label1")
b1 := widget.NewButton("Button1", func() { fmt.Println("button1") })
b1.ExtendBaseWidget(b1)
b2 := widget.NewButton("Button2", func() { fmt.Println("button2") })
b2.ExtendBaseWidget(b2)
label2 := widget.NewLabel("Label3")
labox1 := fyne.NewContainerWithLayout(layout.NewGridLayoutWithRows(3),
fyne.NewContainerWithLayout(
layout.NewCenterLayout(),
label1,
))
labox2 := fyne.NewContainerWithLayout(layout.NewCenterLayout(), label2)
w.SetContent(
fyne.NewContainerWithLayout(
layout.NewBorderLayout(
labox1,
labox2,
nil,
nil,
),
labox1,
labox2,
fyne.NewContainerWithLayout(
layout.NewAdaptiveGridLayout(2),
b1,
b2,
),
),
)
w.Resize(fyne.Size{Height: 320, Width: 480})
w.ShowAndRun()
}