【发布时间】:2017-03-21 07:47:21
【问题描述】:
我对 LibGDX API 有点陌生,我试图在表格中组织标签和 ImageButtons(以及这些表格中的表格)。当我运行应用程序时,ImageButtons 没有被绘制到屏幕上。
我到处搜索,但找不到答案,所以非常感谢帮助。
编辑:这可能是因为我在表格中使用表格,但我没有找到任何关于嵌套表格的信息,或者说实话。
我在 render 中调用了一个方法来保持标签文本的变化,如下所示:
public void drawTable(){
final Table scrollTable = new Table();
scrollTable.addActor(canbtn);
scrollTable.row();
//other buttons
Label.LabelStyle style = new Label.LabelStyle(font, Color.WHITE);
Label.LabelStyle style2 = new Label.LabelStyle(font2, Color.WHITE);
CustomLabel amtLabel = new CustomLabel("" + (int)(game.tot.getSum()), style);
CustomLabel mizcoins = new CustomLabel("Mizcoins", style2);
CustomLabel mpsCount = new CustomLabel(game.totMPS + " MPS", style2);
PerSec can = game.boosts.get("Can").getPerSec();
Table t = new Table();
t.add(drawer(can, canbtn));
t.row();
scroller = new ScrollPane(t);
table = new Table(); //the container table
table.setFillParent(true);
table.add(amtLabel).padTop(50);
table.row();
table.add(mizcoins);
table.row();
table.add(mpsCount);
table.row();
table.add(scroller).fill().expand();//.space(350).padBottom(10);
}
还有drawer()函数:
public Table drawer(PerSec perSec, ImageButton imgbtn){
Label.LabelStyle style = new Label.LabelStyle(font2, Color.WHITE);
Label.LabelStyle style2 = new Label.LabelStyle(font2, Color.WHITE);
Label.LabelStyle style3 = new Label.LabelStyle(font2, Color.RED);
CustomLabel nameLabel = new CustomLabel(perSec.getType(), style);
CustomLabel priceLabel = new CustomLabel("Price: " + perSec.getPrice(), style2);
CustomLabel addsLabel = new CustomLabel("Adds: " + perSec.getDefAddPerSec(), style2);
CustomLabel youHaveLabel = new CustomLabel("You Have: " + perSec.getAmt(), style3);
Table mainTable = new Table();
Table smallTable = new Table();
smallTable.add(priceLabel);
smallTable.row();
smallTable.add(youHaveLabel);
mainTable.add(nameLabel);
mainTable.add(imgbtn);
mainTable.row();
mainTable.add(smallTable);
mainTable.add(addsLabel);
return mainTable;
}
【问题讨论】:
-
弹出的一些内容是:您首先在 canbtn 上执行“addActor”,然后在“drawer()”中将其添加到其他内容中。这推翻了之前的 add 调用,因为一个 actor 只能有 1 个父级。另外 add 和 addActor 的工作方式也不同。 addActor 仅将其作为子项放置。而 add() 创建一个表格单元格,将其添加到其中。使其使用表格的对齐功能。问题可能是:覆盖添加,将其添加到错误的表中。或者添加它的大小为 0。
-
我不太明白你的目的,因为我认为我坚持自己的想法。我将粘贴一个链接,向您展示我的设计目的:imgur.com/a/tpVnZ
标签: android libgdx imagebutton scrollpane