I’ve tried everything there is to try and I’m beginning to suspect this is not really possible.
What I’m looking for is dynamic distribution of N children in a (horizontal) LinearLayout based on their widths. Kind of like a HTML table does it, by dynamically calculating the column widths. Basically I want to turn my ListView into a table with dynamically calculated widths, as such:
<table class="ListView">
<tr class="LinearLayout"><td class="TextView">John:</td><td class="TextView">123-456-789</td></tr>
<tr class="LinearLayout"><td class="TextView">Mike:</td><td class="TextView">321-654-987</td></tr>
<tr class="LinearLayout"><td class="TextView">Sally:</td><td class="TextView">789-456-123</td></tr>
</table>
How do I do something like that in Android? Remember, I don’t just want to split it into two equally long parts. I need the content to determine the column width and fill the entire LinearLayout. Like this (assuming there are only two child elements):
[ [--TextView--] [--------TextView--------] ]
It is not possible using
LinearLayout. You must use aTableLayoutwith all elements in theTableRow' having widthwrap_content`. If your no of rows to be displayed is dynamic, then you have to create and insert rows in the ViewGroup dynamically, otherwise its pretty straight forward for static data.