Taranfx
Taranfx

Reputation: 10437

Android ListView with Multiple Columns aligned properly

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:

Upvotes: 7

Views: 6768

Answers (5)

halxinate
halxinate

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

Dalmas
Dalmas

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

Maxim
Maxim

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

Christine
Christine

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

Code Droid
Code Droid

Reputation: 10472

A Table Layout with a row. The whole idea of table is equal distance.

Upvotes: 0

Related Questions