[ACCEPTED]-Android TableLayout Width-tablelayout

Accepted answer
Score: 60

You may want to define the sizes of the 9 columns by using a weight. So you will define 8 the table layout height to fill parent but 7 for each column you should set the width 6 to "0px" and the weight to the percentage 5 you want the column to span. So assuming 4 you want the first column to be 30% of the 3 screen width you set it's weight to "0.3" and 2 the second column to "0.7".

Try it and see 1 if that works.

Score: 29

The pragmatic way to solve this is to use 4 the stretchColumns and shrinkColumns attributes in TableLayout. Their values should 3 be 0-based indexes of columns.

For example, if 2 you have a two column Table layout and:

  • You would like the second column to fill up with empty space (stretch) so the TableLayout fits the entire parent view on a large screen device
  • You would like the first column to be shrunk (and its contents possibly wrapped / ellipsized) on a small screen device

you 1 would define your TableLayout as:

<TableLayout
    android:id="@+id/my_table_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1"
    android:shrinkColumns="0" >
</TableLayout>
Score: 7

This worked for me..

tableLayout.setColumnShrinkable(1,true);

0

Score: 6
<TableLayout 
android:layout_height="fill_parent" 
android:layout_width="fill_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<TableRow 
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<TextView 
android:layout_width="wrap_content"
android:text="Name " 
android:layout_height="fill_parent">
</TextView>
<EditText 
android:layout_width="0dp"
android:layout_weight="1"
android:hint="name"
android:layout_height="wrap_content" 
>
</EditText>
</TableRow>
</TableLayout>

This code worked for me to align text view 1 on first column and edit text fill parent.

Score: 0

Try this, make sure android:singleLine="false" and android:inputType="textMultiLine":

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:stretchColumns="1">
    <TableRow android:layout_height="wrap_content"
        android:layout_width="fill_parent">

        <TextView android:text="Label:" />
        <EditText android:id="@+id/entry" android:inputType="textMultiLine"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:singleLine="false" />
    </TableRow>
</TableLayout>

0

Score: 0

I had similar problem with EditText on Android 6 2.2. In my case adding android:maxWidth="0sp" property 5 helped. Now EditText field is displayed 4 as I wanted - so it is still of the same 3 size as other EditText fields, but additionaly 2 it is not resized when long text is entered.

Here 1 is my EditText definition:

<EditText android:id="@+id/extra_edit"
       android:padding="3dip"
       android:inputType="textImeMultiLine"
       android:maxWidth="0sp"
       android:layout_width="fill_parent"
       />

More Related questions