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" />
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With