Compact spinner widgets
My application uses a couple of spinner widgets. With limited screen space, they just seemed too large. I tried various ways to make them smaller, like setting padding and layout margins to small values, including zero, but that didn’t help. The empty space around the spinner stayed there no matter what, I was just unable to make it go away.
Then I had the idea to try and change the background. This turned out to be what was needed – it’s the background that defines a spinner’s size, and what looked like margins was just empty pixels in the background image.
So here are my background .png files:
Use them like this:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/slim_spinner_pressed" /> <item android:drawable="@drawable/slim_spinner_normal" /> </selector>
<Spinner ..... android:background="@drawable/selector_slim_spinner" ..... />
This is a screenshot showing my “slim” spinners side-by-side with the regular ones (HTC Hero):
BTW: Digging through Android 1.5 sources, I found a .9.png file that is apparently the stock spinner background. It seems even larger than those shown above. So apparently, HTC had the same idea when tweaking Android for the Hero… they just didn’t go as far.