Spinner moves down when receiving items

I have a simple layout, below is the corresponding fragment. It looks the way I want, as long as the counter is empty. As soon as I add elements to it (at runtime) - it jumps halfway down. Why?

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TableLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="top"
                android:layout_marginTop="10dp" >

                <TableRow
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content" >

                    <TextView
                        android:id="@+id/lbl"
                        style="@style/Label.Plain"
                        android:layout_height="@dimen/button_height"
                        android:layout_marginRight="5dp"
                        android:layout_weight="0"
                        android:gravity="left|center_vertical" />

                    <Spinner
                        android:id="@+id/spinner"
                        style="@style/Spinner"
                        android:background="#ff0000"
                        android:layout_width="fill_parent"
                        android:layout_weight="1" />

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

And this is the "Spinner" style:

<style name="Spinner" parent="@android:style/Widget.Holo.Spinner">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">@dimen/button_height</item>
        <item name="android:textSize">@dimen/spinner_text</item>
        <item name="android:textColor">@color/button</item>
        <item name="android:gravity">center_vertical</item>
        <item name="android:padding">2dp</item>
        <item name="android:maxLines">1</item>
   </style>
+3
source share
1 answer

I don’t understand why, but the problem disappeared as soon as I set the spinner padding to 0dp instead of the 2dp specified by the style.

+1
source

All Articles