rasen58
rasen58

Reputation: 5091

Android TableLayout is being resized

https://i.sstatic.net/C9m5g.jpg

The first image is the way my app looked before I made the EditText into a table row. After I made it into a table row, the row underneath became resized, even though they all have the same weight. However, I want the EditText to be in a table row, so I can I make it even again?

Original xml layout file:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/TableLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="5dp"
    android:shrinkColumns="30"
    android:stretchColumns="20" >


         <EditText
        android:id="@+id/editText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10"
        android:inputType="numberSigned" 
        android:layout_weight="3">

        <requestFocus/>

    </EditText>

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/button7"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="enterNum"
            android:text="@string/num7" />

        <Button
            android:id="@+id/button8"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="enterNum"
            android:text="@string/num8" />

        <Button
            android:id="@+id/button9"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="enterNum"
            android:text="@string/num9" />

        <Button
            android:id="@+id/buttonDiv"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:onClick="enterOp"
            android:text="@string/div" />
    </TableRow>

Changed code:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/TableLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="5dp"
    android:shrinkColumns="30"
    android:stretchColumns="20" >


      <TableRow
        android:id="@+id/tableRow

Upvotes: 0

Views: 919

Answers (1)

Veerababu Medisetti
Veerababu Medisetti

Reputation: 2755

try this code i modified the xml as your requirement


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relativeLayOut"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="5dp" >

    <EditText
        android:id="@+id/editText"
        android:layout_width="fill_parent"
        android:layout_height="50dip"
        android:layout_weight="1"
        android:inputType="numberSigned" >

        <requestFocus />
    </EditText>

    <TableLayout
        android:id="@+id/TableLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/editText"
        android:shrinkColumns="30"
        android:stretchColumns="20" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
             >

            <Button
                android:id="@+id/button7"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="enterNum"
                android:text="7" />

            <Button
                android:id="@+id/button8"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="enterNum"
                android:text="8" />

            <Button
                android:id="@+id/button9"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="enterNum"
                android:text="9" />

            <Button
                android:id="@+id/buttonDiv"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="enterOp"
                android:text="/" />
        </TableRow>
                <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
             >

            <Button
                android:id="@+id/button7"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="enterNum"
                android:text="4" />

            <Button
                android:id="@+id/button8"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="enterNum"
                android:text="5" />

            <Button
                android:id="@+id/button9"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="enterNum"
                android:text="6" />

            <Button
                android:id="@+id/buttonDiv"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="enterOp"
                android:text="*" />
        </TableRow>
                <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
             >

            <Button
                android:id="@+id/button7"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="enterNum"
                android:text="1" />

            <Button
                android:id="@+id/button8"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="enterNum"
                android:text="2" />

            <Button
                android:id="@+id/button9"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="enterNum"
                android:text="3" />

            <Button
                android:id="@+id/buttonDiv"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:onClick="enterOp"
                android:text="-" />
        </TableRow>
    </TableLayout>

</RelativeLayout>

Upvotes: 1

Related Questions