Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping Columns Aligned In All Rows In An Android Table

I've a problem in Android, that i can't solved no matter what i've tried.

Imagine a tablelayout which has 3 tablerows, and each row two textfields.

Image : Couldn't Add Image Here, Due To New User Restrictions

[Right Now Only Focus On "Showing Data"]

I need to align columns in each row equally.

(meaning : r[ 0 ]c[ 0 ].width = r[ 1]c[ 0 ].width = r[ 2 ]c[ 0 ].width etc..)

However, i've different strings in textviews, and some of them are short, some of them long.

Using 0dp as width and 1 as layout_weight values, doesn't solve my problem. in each row (individually) columns are resized.

[See "Current Behaviour"]

Also, giving constant width values (with px or dp) makes everything constant. I don't want that either..

What i want to do is, set all textfields width in a column (in all rows) equally. According to textview which has the longest text value.

If it's not possible with tablelayout & tablerows, is it possible with listview?

How can i do this ?

like image 978
Emir Civas Avatar asked Nov 29 '25 22:11

Emir Civas


1 Answers

Solved It! :)

For someone who will try to do this :

open table_layout in layout.xml and add :

android:shrinkColumns="*"
android:stretchColumns="*"
like image 184
Emir Civas Avatar answered Dec 01 '25 14:12

Emir Civas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!