简体   繁体   中英

Fyne Golang: Resize/Move doesn't do anything

In some cases Resize() or Move() functions doesn't working.

For example

func createUI(application fyne.App) *fyne.Container {
exitBtn := widget.NewButton("Exit", func() { application.Quit() })
rect := canvas.NewRectangle(color.NRGBA{255, 0, 0, 255})

rect.Resize(fyne.NewSize(500, 500))

header := container.NewMax(rect)
nav := container.NewBorder(canvas.NewText("Navigate", color.Black), exitBtn, nil, nil)
body := container.NewCenter(canvas.NewText("Content", color.Black))

return container.NewBorder(header, nil, nav, body)

}

There rect.Resize(fyne.NewSize(500, 500)) is not working properly. 在此处输入图像描述

You have put the Rectangle into a container with a layout - it will control the size and position. If you want to do manual positioning you should use container.NewContainerWithoutLayout . Alternatively you can build a custom layout to position items. As you might see in the docs the Move and Resize are how layouts manage widgets, so your code is being overridden.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM