简体   繁体   中英

Scene2D UI not filling whole screen

In the level selection screen I'm currently working on I can't seem to make the Scene2D UI table fill the whole screen. I've omitted a few bits from the code to reduce the length, but here is the relevant code:

Stage stage = new Stage(new ScreenViewport());

table = new Table();
table.setFillParent(true);
innerTable = new Table();
//Omitted: Add a button to innerTable for each level

ScrollPaneStyle scrollPanelStyle = new ScrollPaneStyle();
scrollPanelStyle.vScrollKnob = new BaseDrawable();
scrollPane = new ScrollPane(innerTable);
scrollPane.setScrollingDisabled(true, false);
scrollPane.setupOverscroll(30f, 30f, 150f);

//Temporarily a restart icon 
Image backButton = new Image(backButtonTexture);
backButton.setScaling(Scaling.fit);
table.add(backButton).height(75f).width(75f).pad(20, 0, 20, 0).left();
table.row();
table.add(scrollPane);

It currently looks like this. The icon isn't as far to the left as I would think it would be with the current code. As far as I'm concerned it should be at 0 on the X axis.

等级选择画面

The same thing is true for the innerTable with the ScrollPane containing all the levels, it doesn't fill the entire screen on the X axis, but it looks like I want it, so it's not really a problem there.

Answer: Adding expandX() to my ScrollPane ended up doing the trick, resulting in this line: table.add(scrollPane).expandX(); . A big thanks to flogy.

I guess the table is stretched properly to your viewport but there is some other misconfiguration. I recommend using the debug mode to get more details (see https://github.com/libgdx/libgdx/wiki/Table#debugging - also use on the back button etc). If you can't find a solution using this method by yourself, please update the screenshot, so we can investigate further. Thanks.

Final solution (see comments):

 table.add(scrollPane).expandX();

The table was already filling the whole screen but the contained scroll panel was not. The table cells adapt to their content by default. By using expandX, we could finally expand the width of the cell that contains the scroll panel to the full table width.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM