TableLayout with layout_width=matchparent not matching parent

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:

  • The third row cell is setting every left cell width.
  • The EditText in the first row starts where the left cell ends (almost at three quarters of the screen width).
  • The second row is given weight 1 each cell, so both cells in the row should measure half the screen, but since the first cell is that wide, the weight is calculated in proportion, so even if you set a weight of 50 for the right cell, you'll never get half the screen because the first cell cannot be smaller than the content on the third cell.