I have several text edits in a table layout. With small values, the TextEdits stretch to the edge of the screen. However, large values cause the TextEdits to expand past the screen edge. How do I keep the textedit width to the screen edge at all times?
<TableLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:stretchColumns="1">
<TableRow android:baselineAligned="true" android:layout_height="wrap_content" android:gravity="center_vertical" android:layout_width="wrap_content">
<TextView android:id="@+id/textView4" android:layout_height="wrap_content" android:text="Perm:" style="@style/PlainText" android:layout_width="wrap_content"></TextView>
<EditText android:id="@+id/f" android:hint="0" android:scrollHorizontally="true"></EditText>
</TableRow>
<TableRow android:layout_height="wrap_content" android:layout_width="wrap_content">
开发者_运维问答 <TextView android:layout_width="wrap_content" android:layout_marginLeft="5dip" android:layout_height="wrap_content" style="@style/PlainText" android:id="@+id/textView5" android:text="w/ repetition:" android:gravity="right"></TextView>
<EditText android:id="@+id/e" android:hint="0" android:scrollHorizontally="true"></EditText>
</TableRow>
<TableRow android:layout_height="wrap_content" android:gravity="center_vertical" android:layout_width="wrap_content">
<TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Combinations:" style="@style/PlainText"></TextView>
<EditText android:id="@+id/d" android:hint="0" android:scrollHorizontally="true"></EditText>
</TableRow>
<TableRow android:layout_height="wrap_content" android:layout_width="wrap_content">
<TextView android:layout_width="wrap_content" android:layout_marginLeft="5dip" android:layout_height="wrap_content" style="@style/PlainText" android:id="@+id/textView6" android:text="w/ repetition:" android:gravity="right"></TextView>
<EditText android:id="@+id/c" android:hint="0" android:scrollHorizontally="true"></EditText>
</TableRow>
<TableRow android:layout_height="wrap_content" android:gravity="center_vertical" android:layout_width="wrap_content">
<TextView android:id="@+id/TextView03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="# of subsets:" style="@style/PlainText"></TextView>
<EditText android:id="@+id/b" android:hint="0" android:scrollHorizontally="true"></EditText>
</TableRow>
<TableRow android:layout_height="wrap_content" android:gravity="center_vertical" android:layout_width="wrap_content">
<TextView android:id="@+id/TextView04" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Pigeonhole:" style="@style/PlainText"></TextView>
<EditText android:id="@+id/z" android:hint="0" android:scrollHorizontally="true"></EditText>
</TableRow>
</TableLayout>
The answer ended up being android:shrinkColumns(#, #) rather than hard coding the size. comment from @akand074 in the answer comments. I found this link which explains why and how this works:
http://growingupwithandroid.blogspot.com/2010/01/how-does-tablelayout-handle-column.html#remindMeAgain
something like this can restrict the no of letters user input into the edit text.
android:maxLength="10"
this will restrict the over flow of characters.
i noticed some are numeric fields. so using
android:inputType="number"
or any other matching option.
UPDATE
something like this will stretch the selected column to take up the remaining space
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1">
<TableRow>
<TextView
android:layout_column="1"
android:text="Open..."
android:padding="3dip" />
<TextView
android:text="Ctrl-O"
android:gravity="right"
android:padding="3dip" />
</TableRow>
</TableLayout>
check this link for more info
http://developer.android.com/resources/tutorials/views/hello-tablelayout.html
精彩评论