2017-06-23 54 views
0

我想將背景添加到帶有標籤的Table,但表格的height = 0。 由於這個原因,背景的height也是0Libgdx添加演員後表格的高度爲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); 

回答

1

嘗試在Table使用pack()方法調用getHeight()

tooltipGroup.pack(); 
table_height = tooltipGroup.getHeight();