androidspinnerandroid-spinner

How to add space between custom spinner items?


I've followed this tutorial Android Widgets: Custom Spinner in Android and made a custom Spinner that has an image and a text view as items, but for some reason there is no space between the items.

At the moment it looks like that when it's not clicked (which is fine):

Custom spinner not clicked

And when I click it, it looks like that:

Custom Spinner clicked

While the default one has plenty of space between the items:

Default spinner clicked

This is the xml code for the spinner:

<Spinner
    android:id="@+id/languageSpinner"
    style="@android:style/Widget.Holo.Light.Spinner"
    android:layout_width="110dp"
    android:layout_height="40dp"
    android:layout_marginStart="30dp"
    android:prompt="@string/select"
    android:spinnerMode="dropdown"/>

And this is the xml for the custom row layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/language"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="18sp"
        android:layout_gravity="center_vertical"
        android:textColor="@color/black"
        android:layout_marginStart="10dp"
        android:layout_marginBottom="2dp"/>
</LinearLayout>

Does anybody have an idea what I do wrong?

EDIT: After some of the suggestions, the space between the items is added but then the item that is selected in the spinner cannot be seen properly, I am attaching an image:

Custom spinner with padding 10 on the layout


Solution

  • custom row layout:

    <?xml version="1.0" encoding="utf-8"?>
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        <LinearLayout 
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="10dp">
            <ImageView
                android:id="@+id/icon"
                android:layout_width="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_height="wrap_content" />
    
            <TextView
                android:id="@+id/language"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="18sp"
                android:layout_gravity="center_vertical"
                android:textColor="@color/black"
                android:layout_marginStart="10dp"
                android:layout_marginBottom="2dp"/>
        </LinearLayout>
        </LinearLayout>