EliteTech
EliteTech

Reputation: 386

editText view not minding layout_width

I am having a layout problem. I have three editText views in a table row. They each have the same attributes, but the first two of them will not mind the layout_width I have set. NOTE: the hints each have the same amount of characters.

ANSWER: Removed table and used nested linear layouts.

    <TableRow
        android:id="@+id/tableRowQuad1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal" >

            <EditText
                android:id="@+id/editTextQuadA"
                android:layout_width="50sp"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="numberDecimal|numberSigned"
                android:hint="@string/hintA" />

            <EditText
                android:id="@+id/editTextQuadB"
                android:layout_width="50sp"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="numberDecimal|numberSigned"
                android:hint="@string/hintB" />

            <EditText
                android:id="@+id/editTextQuadC"
                android:layout_width="50sp"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="numberDecimal|numberSigned"
                android:hint="@string/hintC" />

    </TableRow>

editTextQuadC shows the correct width, but A and B stay the same size unless I make it larger than they appear. They seem to appear about 75-85 sp. Thanks in advance.

Upvotes: 0

Views: 1844

Answers (1)

Shankar Agarwal
Shankar Agarwal

Reputation: 34775

Just change tableRow to LinearLayout and try it work fine as below::

<LinearLayout
        android:id="@+id/tableRowQuad1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal" >

            <EditText
                android:id="@+id/editTextQuadA"
                android:layout_width="50sp"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="numberDecimal|numberSigned"
                android:hint="@string/hintA" />

            <EditText
                android:id="@+id/editTextQuadB"
                android:layout_width="50sp"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="numberDecimal|numberSigned"
                android:hint="@string/hintB" />

            <EditText
                android:id="@+id/editTextQuadC"
                android:layout_width="50sp"
                android:layout_height="wrap_content"
                android:ems="10"
                android:inputType="numberDecimal|numberSigned"
                android:hint="@string/hintC" />

    </LinearLayout>

since if you use table row it is dependent other table row for its width.

Upvotes: 1

Related Questions