I have a tableLayout with two columns and two rows, both rows and the last column have match_parent for width but the layout isn't filling the parent width, it comports itself like it had wrap_content.
Here is the code:
<TableLayout android:layout_width="match_parent">
<TableRow android:layout_width="match_parent">
<TextView
android:layout_width="wrap_content"
android:text="static" />
<EditText
android:layout_width="match_parent"
android:text="text" />
</TableRow>
<TableRow android:layout_width="match_parent">
<TextView
android:layout_width="wrap_content"
android:text="static2" />
<EditText
android:layout_width="match_parent"
android:text="text2" />
</TableRow>
</TableLayout>
What I need to do for each line having the width of the parent?
Ps: the place where I work don't allow me to post my code, so I write a code as close as possible of my code. I don't know if it is right, I can't test.
Try this code, I think it will help you:
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TableRow android:layout_width="match_parent" >
<TextView
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="static" />
<EditText
android:layout_width="match_parent"
android:layout_weight="1"
android:text="text" />
</TableRow>
<TableRow android:layout_width="match_parent" >
<TextView
android:layout_width="fill_parent"
android:layout_weight="1"
android:text="static2" />
<EditText
android:layout_width="match_parent"
android:layout_weight="1"
android:text="text2" />
</TableRow>
</TableLayout>
Also consider if there are other rows whose content is wider than the other rows containing a TextView, since the weight attribute won't work well. Consider this example:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Short Text" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Short Text"
android:layout_weight="1"/>
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reaaaaaaaaaaaaaaaaaaaaaaaaaally lengthy and text"/>
</TableRow>
So this is the result:
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