Reputation: 217
I have a TableLayout
with 3 rows at present and each row has one child, a TextView
. My problem is that the TextViews
widths do not "match_parent"
as they should. I have followed the procedure of not defining heights and widths for them(like the documentation says) but for some reason the problem is still there.
I have opened up the hierarchyviewer
and had a look at the values, the TableRow
fills the width as it should but the TextView
does not fill the row, it is just wrapping the content. The full xml layout is below, does anybody have any ideas?
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:background="@drawable/textlines"
android:text="@string/text1_string"
android:textColor="#000000"
android:padding="5dp">
</TextView>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:background="@drawable/textlines"
android:text="@string/text1_string"
android:textColor="#000000"
android:padding="5dp">
</TextView>
</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:background="@drawable/textlines"
android:text="@string/text1_string"
android:textColor="#000000"
android:padding="5dp">
</TextView>
</TableRow>
</TableLayout>
Also I'll include the xml file for the @drawable/textlines
. Perhaps the problem is in there? (The textlines
code is taken from a solution provided on here concerning a question about borders) I pretty much understand it and I don't think it should affect my problem but I could be wrong. Anyway, here it is:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#FF000000" />
<solid android:color="#FFDDDDDD" />
</shape>
</item>
<item android:top="1dp" android:bottom="1dp">
<shape
android:shape="rectangle">
<stroke android:width="1dp" android:color="#FFDDDDDD" />
<solid android:color="#00000000" />
</shape>
</item>
</layer-list>
Upvotes: 3
Views: 4659
Reputation: 87064
I don't know why that happens but you could avoid that issue either by adding:
android:layout_weight="1"
to your children TextView
s, or by adding:
android:stretchColumns="0"
to your parent TableLayout
.
Upvotes: 13