Android ListView with multiple columns aligned correctly

My Tablet application displays a ListView with several text elements at each position (using a custom cursor adapter). I have about 6-7 columns. What is the best way to give equal spaces for all columns?

Now I tried:

  • The same weight on each TextView. But it never aligns properly.
  • The maximum width used along with the first one, which is still not successful, can be easily overflowed and click the next one on the 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" /> 
+7
source share
5 answers

The scales are fine, but when using the weight of the layout, you need to set android:layout_width to 0dp , otherwise your views may not scale properly.

Also, do not mix fixed widths with layout weights. If you decide to use scales, use them throughout your line layout.

+14
source

It is not recommended to use fixed width and height on Android, let Android do the layout. You can use linearLayout with weights to properly align elements on different lines. use "android: width = 0dp" and use weight to measure different fields. An alternative approach would be to use TableLayout, but that would not be easy. However, it does work.

+3
source

Layout of a table with a row. The whole idea of ​​the table is equal to the distance.

0
source

In my case (for viewing the errorlog) I determined the width for 4 columns (TextViews) from 5 and 1 (in the ice book with the error description) I got weight = 1 to take all the free space. It looks beautiful and without performance overhangs.

0
source

It seems that it is not possible to get a neat table like ListView, since when managing weight different columns of content have different column sizes. Does anyone have an XML solution? Fixed width does not work, since I need to support different screens.

0
source

All Articles