猿问

如何在 GXUI 中设置 LinearLayout 的大小

我正在尝试使用GXUI制作一个网格,我LinearLayout用于行和列,但是我在调整它的大小时遇到了问题。


package main


import (

  "fmt"


  "github.com/google/gxui"

  "github.com/google/gxui/math"

  "github.com/google/gxui/drivers/gl"

  "github.com/google/gxui/samples/flags"

  "github.com/google/gxui/themes/dark"

)


func appMain(driver gxui.Driver)  {

  theme := dark.CreateTheme(driver)


  window := theme.CreateWindow(800, 600, "Grid")

  window.SetScale(flags.DefaultScaleFactor)

  window.OnClose(driver.Terminate)

  size := window.Viewport().SizeDips()


  grid := theme.CreateLinearLayout()

  grid.SetDirection(gxui.TopToBottom)

  grid.SetSizeMode(gxui.Fill)


  for y := 0; y < 4; y++ {

    row := theme.CreateLinearLayout()

    row.SetDirection(gxui.LeftToRight)


    for x := 0; x < 4; x++ {

      label := theme.CreateLabel()

      label.SetText(fmt.Sprintf("%d", y*4+x))


      cell := theme.CreateLinearLayout()

      cell.SetDirection(gxui.TopToBottom)

      cell.SetSize(math.Size{W: size.W/4, H: size.H/4}) // not actually resizes

      cell.AddChild(label)


      row.AddChild(cell)

    }


    grid.AddChild(row)

  }


  window.AddChild(grid)

}


func main() {

  gl.StartDriver(appMain)

}

这是结果:

陪伴而非守候
浏览 195回答 1
1回答
随时随地看视频慕课网APP

相关分类

Go
我要回答