我想使用标签向我的Table
添加背景,但Table 的height = 0
。
因此背景的高度
也是0
。
tooltipGroup = new Table(skin);
tooltipGroup.setWidth(w/6);
Label.LabelStyle headerStyle = new Label.LabelStyle(headerFont, Color.GREEN);
Label headerLabel = new Label(effect.getName(), headerStyle);
headerLabel.setWidth(w/6);
headerLabel.setX(20);
headerLabel.setWrap(true);
headerLabel.setAlignment(Align.topLeft);
tooltipGroup.add(headerLabel).width(w/6).row();
Label.LabelStyle style = new Label.LabelStyle(font, Color.WHITE);
Label descriptionLabel = new Label(effect.getDescription(), style);
descriptionLabel.setWidth(w/6);
descriptionLabel.setWrap(true);
descriptionLabel.setAlignment(Align.topLeft);
descriptionLabel.setPosition(20, -descriptionLabel.getHeight());
tooltipGroup.add(descriptionLabel).width(w/6).fill(true);
tooltipGroup.setPosition(mouseX, h - mouseY);
Drawable background = skin.getDrawable("tooltip_background");
tooltipGroup.setBackground(background);
stage.addActor(tooltipGroup);
最佳答案
在调用 getHeight()
之前尝试在 Table
上使用 pack()
方法
tooltipGroup.pack();
table_height = tooltipGroup.getHeight();
关于java - 添加actors后Libgdx Table的高度为0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44720545/