gpt4 book ai didi

go - 如何使用 Fyne 制作扩展和拉伸(stretch)的布局框

转载 作者:行者123 更新时间:2023-12-01 22:07:26 25 4
gpt4 key购买 nike

我想要用于布局小部件的扩展和拉伸(stretch)框,以便我的应用程序如下所示:
enter image description here

IE。顶部和中间的盒子在两个方向上都很长。

我尝试将此代码与 Box 一起使用(因为我没有在 documentation 中找到任何“免费”布局):

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.NewVBoxLayout(), label1),
fyne.NewContainerWithLayout(layout.NewHBoxLayout(), layout.NewSpacer(), b1, b2, layout.NewSpacer()),
label2),
)

w.ShowAndRun()
}

但这绝对不是一回事:

enter image description here

fyne 是否支持这种布局以及如何正确执行?

最佳答案

enter image description here

像这样?或者描述更多细节。

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()
}

enter image description here

关于go - 如何使用 Fyne 制作扩展和拉伸(stretch)的布局框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60560906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com