I have the following LinearLayout below. I use it for a row in a ListView.
I have set the Textview's weight to 1 so they should all be of equal width.
The problem is when some of the textviews have more characters in, the width of the textview changes. This has an overall effect on how the ListView appears, as in each row the data in not lined up correctly. (i have headings above the ListView).
when some of the TextViews have more text in them, there is still space either side of the text and the textview just gets bigger, which i don't want as i've set the weights to 1 each.
Is there a way of fixing the width of each textview so it doesn't change according to the length of text in it?
thanks in advance
Matt
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<TextView
android:id="@+id/rowstarttimeweeksum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="2" />
<TextView
android:id="@+id/rowplannedcallsweeksum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:layout_weight="1" />
<TextView
android:id="@+id/rowncrsweeksum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:layout_weight="1" />
<TextView
android:id="@+id/rowqasweeksum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:layout_weight="1"/>
<TextView
android:id="@+id/rowplannedhoursweeksum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2:33"
android:layout_weight="1"
android:gravity="right"/>
<TextView
android:id="@+id/rowactualcallsweeksum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2"
android:layout_weight="1"
android:gravity="right"/>
<TextView
android:id="@+id/rowactualhourssweeksum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2:01"
android:layout_weight="1"
android:gravity="right"/>
</LinearLayout>
One small change and your problem is solved
change width of all TextView
from wrap_content
to 0dp
android:layout_width="0dp"
Whenever you will set height/width to 0dp
, it will manage height/width of view as per android:layout_weight
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