Tautvydas Jalinskas
Tautvydas Jalinskas

Reputation: 129

Libgdx Table expandX() expands all rows

I have a table of buttons 5x4. I've added only one button in the first row and expanded it to X so it would take up the whole row and be in the center of the row.

The problem is when you expand the button that is the only one in the row to X "expandX()" the other rows expand to x too!

Is there a way to center, expand, align only one actor in the row?

Upvotes: 0

Views: 193

Answers (1)

Tenfour04
Tenfour04

Reputation: 93779

You are not expanding the actor, only the cell that contains it.

Note that every row of a table has the same number of columns. A table is a regular grid with no staggered column widths. It sounds like what's actually happened is you haven't called colspan on your first button's Cell, so when the first column gets expanded, it pushes the remaining four columns over.

If you want the button in the first row centered across the whole table, you need to call colspan(5) on its Cell. This makes the Cell take up all five columns.

Then if you call expandX() on it, it will cause all five columns to expand. From your description, it sounds like you don't want to do that, and shouldn't be using expandX at all.

If you want your button to be the same width as your whole table, but you don't want your table to be bigger than what's necessary to contain the stuff in the lower rows, then use fillX on the button's cell, not expandX.

Upvotes: 1

Related Questions