【问题标题】:LinearLayout analog inside Table in LibGDXLibGDX 中 Table 内的 LinearLayout 模拟
【发布时间】:2012-11-29 07:29:07
【问题描述】:

我想在 LibGDX 中使用以下布局的 scene2d 包创建一个游戏菜单屏幕

|    label    |
| btn btn btn |
|    label    |

我的代码如下:

Table table = getTable();
table.add(label1);
table.row();
table.add(button1);
table.add(button2);
table.add(button3);
table.row();
table.add(label2);
table.row();

但我得到的不是我想要的:

| label       |
| btn btn btn |
| label       |

原因是因为每个table.add() 方法调用都会创建一个新的单元格。但我想将我所有的 3 个按钮放在一个单元格中。我怎样才能达到预期的结果,可能是在 LibGDX 中存在 LinearLayout 之类的东西或其他什么?

【问题讨论】:

    标签: android layout libgdx scene2d


    【解决方案1】:

    在调用add(label);时返回给你的单元格上调用colspan(3)

    例如

    Cell cell = table.add(label1);
    cell.colspan(3);
    

    顾名思义,这设置单元格将跨越多少列。 您可能还需要通过调用 cell.center(); 来设置单元格的对齐方式

    您可以将这些调用串在一起,因为它们都返回相同的单元格对象..

    table.add(label1).colspan(3).center();
    

    似乎没有针对 libgdx 记录 Cell 类。我只是继续查找 here 的源代码

    现在可以在here 找到单元类文档。官方文档中似乎确实缺少它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-16
      • 2019-06-04
      • 1970-01-01
      • 1970-01-01
      • 2014-09-18
      • 1970-01-01
      • 2015-04-23
      • 2011-08-18
      相关资源
      最近更新 更多