1

I have a TextView and EditText, which needs to be aligned in a row with proper span.

In current layout, EditText is aligned , but appears shrinked, not taking remaining width

enter image description here

Xml:

 <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        tools:style="@style/AppTheme"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp">

        <TableRow>
            <TextView
                style="@style/AppTheme.DetailInfo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="New Password:" />
            <EditText
                style="@style/AppTheme.TextBox"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:inputType="textPassword"
                android:maxLines="1"
                android:text= "@={profile.password}"/>
        </TableRow>
   </TableLayout>
Rk R Bairi
  • 1,289
  • 7
  • 15
  • 39
  • 1
    could be because the width is set to `wrap_content` and the edittext is empty at the moment – wick.ed Jun 29 '17 at 21:43
  • You can use stretchcolumns and shrinkcolumns property https://stackoverflow.com/questions/32331368/how-do-androidshrinkcolumns-and-androidstretchcolumns-work – wick.ed Jun 29 '17 at 21:47

1 Answers1

2

If you want the EditText to fill the remaining space, you should set its layout_width = "0dp" and layout_weight = "1". See:

https://developer.android.com/guide/topics/ui/layout/linear.html#Weight

"For example, if there are three text fields and two of them declare a weight of 1, while the other is given no weight, the third text field without weight will not grow and will only occupy the area required by its content."

Edit: If you want the beginning of your edittexts to be aligned, you should apply the same weight to all of your textviews and the same weight to all of your edittexts. The original answer will simply fill the remaining space without keeping the beginning of the edittexts aligned.

andrewoid
  • 76
  • 3