Libgdx table is too small, does not fill the viewport

I am trying to use a table to create menus with buttons and shortcuts lined up. I use the latest libgdx nightly builds that have changed the table APIs (among other things).

Here is the code in my screen constructor:

this.mStage = new Stage(); this.mTable = new Table(); this.mTable.setFillParent(true); this.mTable.debugTable(); this.mStage.addActor(this.mTable); // now I add some stuff to the table // ... 

My resize function is as follows:

 this.mStage.setViewport(width, height, true); this.mTable.setFillParent(true); this.mTable.invalidate(); 

The My render function has the following:

 System.out.println("Table size is " + this.mTable.getWidth() + " by " + this.mTable.getHeight()); this.mStage.draw(); Table.drawDebug(); 

Although my console shows the correct size:

 Table size is 480.0 by 640.0 

The size of the table is compressed around its children and does not apply to the correct size of 480x640.

Any ideas?

+4
source share
1 answer

Answering my question for the benefit of others. The way I added widgets to the table was wrong:

 this.mTable.row(); this.mTable.add(button).fillX(); 

I needed to call the fillX() row() method:

 this.mTable.row().fillX(); this.mTable.add(button); 

Hope this helps someone.

+5
source

Source: https://habr.com/ru/post/1437103/


All Articles