tags:

views:

34

answers:

1

I have a TableLayout with three columns that represents a form with

requiredSymbol | label | inputfield.

I want the input field to fill the remaining width of the screen right to the label. So far the only solution I found is this

<TableLayout android:layout_height="wrap_content"
       android:layout_width="fill_parent" 
       android:stretchColumns="2">
    <TableRow>
                    <TextView android:text="@string/requiredSymbol"
                              />
     <TextView android:text="@string/Name"
                              android:textColor="@color/orange"
                              android:gravity="left|center_vertical"
         />
     <EditText android:id="@+id/contactName"
         android:inputType="text|textPersonName"
                              android:ellipsize="end"
                            android:singleLine="true"
                            android:scrollHorizontally="true"
                            android:maxWidth="1sp"
                            />
    </TableRow>

The maxWidth needs to be there are some value, which is actually ignored. Then the stretchColumns value does its thing nicely. Note that this also works if the content of the EditText would otherwise make the table span beyond the screen border (imho a bug..).

This works nicely now but seems a little bit of a hack to me. Is there a better way?