Android TableLayout: maintaining column width between different tables

I have two TableLayouts, one above the other, in my view. I want them to act as a single table in order to calculate the width of the columns, but displayed separately with a gap between them (and the main view of the screen) for aesthetic reasons.

Each table has 3 columns, and I want the column widths to be automatically set depending on the content, but I just want the columns to align well with the same width in both tables.

Currently, my tables look like this:

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

But I want them to look like this:

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

The only way I can get what I want is to apply a fixed width to the columns in the questions, but it is detrimental to the fact that TableLayout calculates the widths for me.

Is it possible?

+6
android width tablelayout
source share
2 answers

You should seriously consider cheating. Stick to a row in the table that looks identical to your background, and no one will know that these are not two tables with a gap between them. You may have to do some sort of action with borders, but I suspect that this is not only possible, but also easier than linking two independent table objects.

+2
source share

I'm not sure if this works in every case, but you can try setting the weight of the layout of the three components that you have as table cells. If you use the same weight for each column, they must be the same size.

Example: Android: layout_weight = "0.5"

0
source share

All Articles