Reputation: 10437
My Tablet app shows a ListView with multiple TextViews in each line item (using custom cursor adapter). I have around 6-7 columns, What is the best way to give equal spaces to all columns?
Right now I tried:
Used max width along with 1st, still no luck, one can easily overflow and push the next one to right.
<TextView
android:layout_width="20dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="column 1"
android:textSize="22sp" />
Upvotes: 7
Views: 6768
Reputation: 1559
It looks like it's impossible to get neat looking table like ListView, as with the weight management different content columns are of a different columns size each. Anyone have an XML solution? Fixed width is not working, as I need to support various screens.
Upvotes: 0
Reputation: 26547
Weights are fine, but you have to set android:layout_width
to 0dp
every time you use a layout weight, else your views may not be scaled properly.
Also, don't mix fixed widths with layout weights. If you choose to use weights, use them everywhere in your row layout.
Upvotes: 14
Reputation: 4214
In my case (for errorlog view) I specified width for 4 columns (TextViews) from 5 and 1 (in the diddle with error description) got weight=1 to take all available space. It looks nice and no performance lugs.
Upvotes: 0
Reputation: 5575
It's not good practice to use fixed widths and heights on Android, let Android do the layout. You can use a linearLayout with weights in order to properly aline items in different rows. use "android:width=0dp" and use weight to dimension the various fields. An alternative approach would be to use a TableLayout, but that's kind of tricky. It does work, however.
Upvotes: 3
Reputation: 10472
A Table Layout with a row. The whole idea of table is equal distance.
Upvotes: 0