Pregunta

I have the following problem with a TableLayout in my App. The TableRows sometimes have completely different heights although the code is the same and the content is the same as well. Here is a snippet of my code (cut out the other rows) and for better understanding two pictures (Pink color is the size of the textViews):

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:shrinkColumns="*"
    android:stretchColumns="*" >

    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#F0FFF0"
        android:gravity="center_vertical"
        android:paddingBottom="3dp"
        android:paddingTop="3dp" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#FF00FF"
            android:gravity="right"
            android:paddingRight="3dp"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:background="#FF00FF"
            android:ems="10"
            android:gravity="center"
            android:imeOptions="actionNext"
            android:inputType="numberSigned"
            android:maxLength="1"
            android:singleLine="true" >

        </EditText>

        <TextView
            android:id="@+id/textView3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#FF00FF"
            android:gravity="left"
            android:paddingLeft="3dp"
            android:textAppearance="?android:attr/textAppearanceSmall" />

    </TableRow>      

    <TableRow
        android:id="@+id/tableRow5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#E0EEE0"
        android:gravity="center_vertical"
        android:paddingBottom="3dp"
        android:paddingTop="3dp" >

        <TextView
            android:id="@+id/textView8"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#FF00FF"
            android:gravity="right"
            android:paddingRight="3dp"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <EditText
            android:id="@+id/editText4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:background="#FF00FF"
            android:ems="10"
            android:gravity="center"
            android:imeOptions="actionNext"
            android:inputType="numberSigned"
            android:maxLength="1"
            android:singleLine="true" >

        </EditText>

        <TextView
            android:id="@+id/textView9"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#FF00FF"
            android:gravity="left"
            android:paddingLeft="3dp"
            android:textAppearance="?android:attr/textAppearanceSmall" />

    </TableRow>    
    <TableRow
    android:id="@+id/tableRow10"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#F0FFF0"
    android:gravity="center_vertical"
    android:paddingBottom="3dp"
    android:paddingTop="3dp" >

    <TextView
        android:id="@+id/textView18"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#FF00FF"
        android:gravity="right"
        android:paddingRight="3dp"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <EditText
        android:id="@+id/editText9"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.25"
        android:background="#FF00FF"
        android:ems="10"
        android:gravity="center"
        android:imeOptions="actionNext"
        android:inputType="numberSigned"
        android:maxLength="1"
        android:singleLine="true" >

    </EditText>

    <TextView
        android:id="@+id/textView19"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#FF00FF"
        android:gravity="left"
        android:paddingLeft="3dp"
        android:textAppearance="?android:attr/textAppearanceSmall" />

</TableRow>
</TableLayout>
</ScrollView>

enter image description here enter image description here

You can see in the first picture that tableRow2 is filled with a 2-lined textView and has a very small padding (red hachures), tableRow5 has only 1-lined entries and tableRow10 as well, but the height of tableRow10 is much higher (blue hachures).

In the second picture you see the exact same layout just with changed sequenced entries and the heights of the rows are completely different. I can't get any pattern why this is happening, I'm changing the sequence of the entries and sometimes it is bigger, sometimes smaller.

¿Fue útil?

Solución

Okay, changing the ScrollViews attributes from

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >

to

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

seems to fix this issue. I just don't understand why ... :)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top