Add more space between items in Android Spinner without custom style?

Jim picture Jim · Mar 23, 2013 · Viewed 35.3k times · Source

I have an Android application I'm writing for a Concrete company that will be used for clocking in and out. I've used some spinners to select things like Work Site and Job from drop downs, but I'm worried that the items in the spinners are too close together and will be difficult for the employees to select the right item.

I'd like to give just a bit more space between the items in the spinner, but don't want to go through all the trouble of making a custom style, because really I want the spinner to look and behave exactly like the default except just having a little bit more padding, and it's a lot of work to have to make a custom style just for that.

Is there any simple change I can make, like setting some property of the spinner? I've tried setting the spinner type to Dialog, but it just shows the list with the same amount of spacing, only not attached to the spinner control.

Answer

Jim picture Jim · Mar 28, 2013

I believe Pragnani's answer is correct, but this is how I actually implemented it...

-In RES/layout, created an XML layout with just a textview in it, like shown below. This textview has the custom size / padding that I want.

spinner_row.xml

  <?xml version="1.0" encoding="utf-8"?>
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/cust_view"
        android:minWidth="246dp"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:gravity="left|center_vertical"
        android:textColor="@android:color/black"    
        android:textSize="20sp"
        android:paddingLeft="4dp"
        android:textIsSelectable="false"/>

Then in the activity where I load my data into the spinner, when I create an ArrayAdapter for my spinner, I pass the custom textview as the second parameter to the ArrayAdapter constructor.

Spinner spinClockInWorkSite = (Spinner)findViewById(R.id.spinClockInWorkSite);
ArrayAdapter spinClockInWorkSiteAdapter = new ArrayAdapter(this, R.layout.spinner_row, this.workSiteList);
spinClockInWorkSite.setAdapter(spinClockInWorkSiteAdapter);

So now the spinner uses my custom textview that's defined in spinner_row.xml for each item in the list.

This ended up being more straight-forward for my needs than playing with the style.