[英]Libgdx adding a cell to a table
I'm trying to add label here 我正在尝试在此处添加标签
Label missionTitle = new Label(mission.title, skin);
Label missionDesct = new Label(mission.desct, skin);
Label remainDay = new Label(TaskManager.getRemainMissionDay(mission.deadLine) + "day remain", skin);
missionDesct.setFontScale(width * 1.4f / 1080);
remainDay.setFontScale(width * 1.2f / 1080);
missionDesct.setWrap(true);
Table table = new Table();
table.debug();
table.background(new TextureRegionDrawable(new TextureRegion(new Texture("image/imgray.png"))));
table.add(missionTitle).width(width / 1.1f);
table.row();
table.add(missionDesct).width(width / 1.1f);
table.row();
table.add(remainDay).width(width/2.3f).left();
for that i'm adding this lines; 为此,我要添加这行;
Label goldLabel = new Label("30 gold", skin);
table.add(goldLabel);
How can i add a new cell over there? 如何在那添加新的单元格? I tried to adding ".width(width/2);"
我尝试添加“ .width(width / 2);” but it's not working.
但它不起作用。
...
table.row();
table.add(remainDay).width(width/2.3f).left();
Label goldLabel = new Label("30 gold", skin);
table.add(goldLabel).width(width/2.3f);
You can do that by creating a table with the 2 labels and then adding the table into the container table. 您可以通过创建带有2个标签的表,然后将该表添加到容器表中来实现。
Example - 范例-
Table nestedTable = new Table();
nestedTable.add(remainDay).width(THE_WIDTH);
nestedTable.add(goldLabel).width(THE_WIDTH);
mainTable.add(nestedTable);
You can play around more with this to get the desired result :) 您可以与此玩更多,以获得所需的结果:)
This class can also help - HorizontalGroup 此类也可以提供帮助-HorizontalGroup
Finally i understand my mistake.I was trying to add 2 cell to a row.But that was effecting the other row's cell count.I changed my code to this and solved; 终于我明白了我的错误。我试图在一行中添加2个单元格。但这影响了另一行的单元格计数。我将代码更改为此并解决了;
Table table = new Table();
table.background(new TextureRegionDrawable(new TextureRegion(new Texture("image/imgray.png"))));
table.add(missionTitle).width(width/1.5f).left();
table.add(new TextButton("!", skin)).height(height/23).width(width / 5).right();
table.row().fillX();
table.add(missionDesct).expandX();
table.add(goldAndExp).right();
table.row();
table.add(remainDay).left();
I'll be happy if someone fix my grammar problems. 如果有人解决我的语法问题,我会很高兴。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.