java - 添加actors后Libgdx Table的高度为0

标签 java libgdx

我想使用标签向我的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/

相关文章:

java - libgdx 和 box2d 中多边形内的多边形

java - Dagger2子组件如何注入(inject)到Fragment中?

java - 是否为线程更新了公共(public)静态变量? (它是线程安全的吗?)

java - 三星 Galaxy Tab 7.0 在从相机 Intent 返回时重启应用程序

java - 覆盖绘图顺序 scene2D 的舞台

java - libgdx 中的碰撞处理程序检测得太早

java - 如何在 lambda 迭代和普通循环之间做出决定?

java - 使用ajax从php页面调用servlet

java - 更新循环更新对象而不是删除它

java - LibGDX:如何更改单个 Sprite 的颜色?