1
\$\begingroup\$

For my game's (mostly GUI based) UI i am using table from Scene2D in libGDX. I want independent column sizes in my table but first cell width is the width for all other rows in column. Is it possible to have a table in Scene2D with independent cell width in each row? For example, first cell in first row should have 10% width and first cell in second row should have 15% width. I tried using Horizontal Groups, Containers but they make my code too shabby and cluttered.enter image description here

\$\endgroup\$
  • \$\begingroup\$ Hey, did you find out how to do this? I'm kind of having the exact problem. \$\endgroup\$ – WeirdElfB0y Jul 1 '16 at 8:24
  • 1
    \$\begingroup\$ i had to insert table within table. In whichever row you need different column size, insert a table of size 1 x N (N=no. of columns). I hope i am clear. \$\endgroup\$ – Karani.pranay Jul 2 '16 at 4:20
  • \$\begingroup\$ pastebin.com/yBLDNvG2 \$\endgroup\$ – Karani.pranay Jul 2 '16 at 4:30
1
\$\begingroup\$

There is an option to do this:

First of all you need to find out what your smallest size of a column is, therefore you have to merge all rows into one and pick the smallest width of all columns.

merging rows the numbers in the picture are displaying the width of the columns.

Knowing your smallest width (in my example it's displayed as 1) allows you to create a table with as many columns as you need. (for my example its 17 columns -> width / 17).

Now use:

table.add(Actor).colspan(#); //replace # with the amount of columns you want to span

In my example this would be:

Table t = new Table(skin);
t.add(Actor0).colspan(1).expandX();
t.add(Actor1).colspan(5).expandX();
t.add(Actor2).colspan(3).expandX();
t.add(Actor3).colspan(3).expandX();
t.add(Actor4).colspan(2).expandX();
t.add(Actor5).colspan(3).expandX().row();
t.add(Actor6).colspan(2).expandX();
t.add(Actor7).colspan(2).expandX();
t.add(Actor8).colspan(5).expandX();
t.add(Actor9).colspan(4).expandX();
t.add(Actor10).colspan(3).expandX();
t.add(Actor11).colspan(1).expandX();

output looks as follows: (note that I added a row with equally sized columns for reference above) output

|improve this answer|||||
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.