FormLayout布局和FormItem对比
FormLayout布局
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
)
func main() {
myApp := app.New()
myWindow := myApp.NewWindow("VPN")
userLable := widget.NewLabel("USERNAME")
userEntry := widget.NewEntry()
passLable := widget.NewLabel("PASSWORD")
passEntry := widget.NewPasswordEntry()
c := container.New(layout.NewFormLayout(), userLable, userEntry, passLable, passEntry)
myWindow.SetContent(c)
myWindow.Resize(fyne.NewSize(300, 300))
myWindow.Show()
myApp.Run()
}
效果图如下:
FormItem
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
)
func main() {
myApp := app.New()
myWindow := myApp.NewWindow("VPN")
userEntry := widget.NewEntry()
userL := widget.NewFormItem("USERNAME", userEntry)
passEntry := widget.NewPasswordEntry()
passL := widget.NewFormItem("PASSWORD", passEntry)
form := widget.NewForm(userL, passL)
c := container.NewVBox(form)
myWindow.SetContent(c)
myWindow.Resize(fyne.NewSize(300, 300))
myWindow.Show()
myApp.Run()
}
效果图如下:
总结
1.这2个都能达到同样的效果。
2.角色定位:FormLayout是布局方式,负责安排对象的位置和大小;FormItem是表单项,负责收集用户输入的数据。