Center Layout

layout.CenterLayout organises all items in its container to be centered in the available space. The objects will be drawn in the order the are passed to the container, with the last being drawn top-most.

The center layout causes all items to stay at their minimum size, if you wish to expand items to fill the space then see layout.MaxLayout.

Example Code

            
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package main

import (
	"image/color"

	"fyne.io/fyne"
	"fyne.io/fyne/app"
	"fyne.io/fyne/canvas"
	"fyne.io/fyne/layout"
	"fyne.io/fyne/theme"
)

func main() {
	myApp := app.New()
	myWindow := myApp.NewWindow("Center Layout")

	img := canvas.NewImageFromResource(theme.FyneLogo())
	img.FillMode = canvas.ImageFillOriginal
	text := canvas.NewText("Overlay", color.Black)
	content := fyne.NewContainerWithLayout(layout.NewCenterLayout(),
		img, text)
	myWindow.SetContent(content)
	myWindow.ShowAndRun()
}