Android TableLayout: preserve column widths between different tables
Asked Answered
J

2

6

I have two TableLayouts, one above the other, in my View. I want them to act as a single table for the purpose of calculating column widths, but appear separately with a gap between them (and the main View background showing through) for aesthetic reasons.

Each table has 3 columns, and I want the column widths sized automatically depending on content, but I just want the columns to line up nicely with the same widths in both tables.

At the moment my tables look like this:

+---------------------------+
|      |                |   |
|      |                |   |
+---------------------------+

+---------------------------+
|          |            |   |
|          |            |   |
|          |            |   |
|          |            |   |
+---------------------------+

But I want them to look like this:

+---------------------------+
|         |             |   |
|         |             |   |
+---------------------------+

+---------------------------+
|         |             |   |
|         |             |   |
|         |             |   |
|         |             |   |
+---------------------------+

The only way I can see of getting what I want is to apply a fixed width to the columns in questions, but that defeats the point of having the TableLayout calculate the widths for me.

Is it at all possible?

Jackstay answered 31/7, 2010 at 13:58 Comment(0)
A
2

You should seriously consider cheating. Stick in a table row that looks identical to your background, and nobody will know that it isn't two tables with a gap between them. You may have to do some fiddling with borders, but I suspect that it's not only possible, but easier than linking two independent table objects.

Arreola answered 12/10, 2010 at 3:49 Comment(1)
This is probably your best bet.Parsley
O
0

I'm not sure if this works in every case but you could try setting layout weight of the 3 components you have as table cells. If you use same weight on each column they should endup same size.

example: android:layout_weight="0.5"

Outpoint answered 10/10, 2010 at 22:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.