我在表格中添加了一些图像,侧面带有标签,但这些图像将标签推得很远,从而扭曲了整体布局。
图像分辨率为 640x640。
我尝试使用单元格函数并尝试填充不同的行和列(有点有效,但这不是我想要的,因为它取代了整个表格的组件)并且我已经阅读了表格文档GitHub here ,但是我仍然遇到同样的问题。
这是表格布局代码(在类构造函数中初始化表格)
int[] values;
ArrayList<Label> labels = new ArrayList<>();
//just setting up labels with according values, not really important
if (label.getText().toString().contains("Conjurer")) values = new int[]{200, 9, 10, 15, 15};
else if (label.getText().toString().contains("Monk")) values = new int[]{300, 14, 15, 11, 8};
else values = new int[]{320, 14, 17, 9, 13};
//creating new labels and adding to list
for (int i = 0; i <= 4; i++) {
Label l = new Label(String.valueOf(values[i]), UI.createNewLabelStyle(font, Color.WHITE)); //temp label to add
labels.add(l);
}
Image healthIcon = new Image(stat_atlas.findRegion("healthIcon"));
Image defenseIcon = new Image(stat_atlas.findRegion("defenseIcon"));
Image attackIcon = new Image(stat_atlas.findRegion("attackIcon"));
Image magicAttackIcon = new Image(stat_atlas.findRegion("magicAttackIcon"));
Image magicDefenseIcon = new Image(stat_atlas.findRegion("magicDefenseIcon"));
table.setDebug(true);
table.row();
table.add(healthIcon).height(60f).width(60f);
table.add(labels.get(0));
table.row();
table.add(attackIcon).height(60f).width(60f).right();
table.add(labels.get(1));
table.row();
table.add(defenseIcon).height(60f).width(60f).right();
table.add(labels.get(2));
table.row();
table.add(magicAttackIcon).height(60f).width(60f).right();
table.add(labels.get(3));
table.row();
table.add(magicDefenseIcon).height(60f).width(60f).right();
table.add(labels.get(4));
table.row();
我想要的是找到一种方法,让图像不跨越这么大的区域(红线应该只封装图像而不超出它)
非常感谢!
最佳答案
发生的情况是您的后退按钮仅占据一列,因此第二列中的所有标签都必须显示在其右侧。添加后退按钮时,对返回的 Cell 调用 colSpan(2)
。此外,当您添加标签时,您可能需要在其返回的单元格上调用 left()
,以便它们插入图像。
由于表分配列的额外空间的方式,这不一定会将所有内容居中。如果您需要将其全部居中,那么实际上您需要一个内部表格来容纳除“后退”按钮之外的所有内容。
关于java - 添加到表行中的图像占用了比预期更多的行空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57823795/