【发布时间】:2014-02-27 07:57:29
【问题描述】:
我在 libgdx 中有一个表,它应该有 6 个按钮,分为 2 行。这是我的代码:
elementsTable.clear();
String[] colors = new String [6];
colors[0] = "red";
colors[1] = "orange";
colors[2] = "yellow";
colors[3] = "purple";
colors[4] = "blue";
colors[5] = "green";
String category = currentCategory.name();
category = category.substring(0, category.length()-1).toLowerCase(); //removes the last character because otherwise there would be an extra 's'
int count = 0;
for(String color : colors) {
ButtonStyle buttonStyle = new ButtonStyle();
buttonStyle.up = cellsSkin.getDrawable(category + "_" + color);
Button button = new Button(buttonStyle);
button.addListener(toolBoxListener);
button.setName(category + "_" + color);
button.setSize(toolBoxButtonSize, toolBoxButtonSize);
elementsTable.add(button).pad(toolBoxButtonPadding);
count ++;
if (count == Math.ceil((colors.length/2d))) elementsTable.row();
}
这就是填充物。我的按钮有 6 种不同的颜色,所以我用颜色名称遍历数组以访问皮肤以获取按钮的可绘制对象。这部分似乎有效,因为当我调试并查看表格时,它有 6 个大小合适的按钮。
然后我设置我的桌子的位置和大小并将它添加到舞台上。:
elementsTable.setSize(toolBoxWidth, 500/(float)(3*toolBoxButtonSize+6*toolBoxButtonPadding)*elementsTable.getHeight());
elementsTable.setPosition(195, 30);
stage.addActor(elementsTable);
舞台有一个正交相机组,可以很好地缩小物体。
但是,我得到的是:
另一个奇怪的问题是,当我在调试模式下查看表格的高度和宽度时,它显示为 0,即使其中的元素都具有正确的大小。
谁能帮帮我?
如果您对此问题还有任何疑问,请提出!我试图给出详细的描述,但我很乐意回答您的问题。
【问题讨论】:
标签: java android layout libgdx