How can I make the spinner width same as largest available item width

Solution 1:

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.

Solution 2:

I merely "solve" the problem by using

<Spinner
    android:id="@+id/country_spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:minWidth="200dp"
    android:layout_marginBottom="10dp" />

200dp is just try-n-error value, to ensure all items in the drop down list are visible.

Solution 3:

In such cases where you want to list all country or have big list
Try: spinnerMode="dialog" as shown below:

<Spinner
    android:id="@+id/spinnerId"
    android:layout_width="wrap_content"
    android:dropDownWidth="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="10dp"
    android:spinnerMode="dialog"/>