I realize even I use wrap_content
for my spinner (I avoid using match_parent
as I do not want the spinner overly long), and using match_parent
for spinner's item view and drop down item view,
I still find the spinner's width is not same as largest item's width
As you can see, the UnitedKingdom
is not fit.
So, if I select the UnitedKingdom
, only the spinner's will resize
How can I make the spinner resize to the largest available item width, even without being explicitly selecting the largest item?
My spinner XML is
<Spinner android:id="@+id/spinner1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" />
and my spinner's views XML are
<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text_view_0" style="?android:attr/spinnerItemStyle" android:singleLine="true" android:layout_width="match_parent" android:layout_height="wrap_content" android:drawablePadding="10dp" android:gravity="center_vertical" />
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/checked_text_view_0" style="?android:attr/spinnerDropDownItemStyle" android:singleLine="true" android:layout_width="match_parent" android:layout_height="48dp" android:minHeight="48dp" android:drawablePadding="10dp" />
You should be able to get the effect you want by specifying the width of the dropdown as WRAP_CONTENT
:
<Spinner android:id="@+id/spinner1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:dropDownWidth="wrap_content" android:spinnerMode="dropdown" />
This will measure up to 15 items in the spinner's adapter to determine the width it should use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With