spinner dropdown start from top of spinner

Kishore Jethava picture Kishore Jethava · Dec 12, 2015 · Viewed 10.9k times · Source

Problem is Spinner dropdown list start from top line of Spinner but it should be start from bottom line of Spinner

Normal state

enter image description here

After Click

enter image description here

Spinner xml code

<Spinner
    android:id="@+id/spnSelectLanguage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="8dp"
    android:layout_marginTop="16dp"
    android:spinnerMode="dropdown"
    android:background="@drawable/spn_lang_dropdown_selector"
    android:gravity="center_vertical"
    android:popupBackground="#EAEAEA"
    android:textColor="#54a4db" />

Code

Spinner spnSelectLanguage = (Spinner)rootView.findViewById(R.id.spnSelectLanguage);
    ArrayAdapter<String> adapterLanguage= new ArrayAdapter<String> (context,R.layout.layout_lng_spinner_item,new String[]{"English","Arabic"});
    adapterLanguage.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spnSelectLanguage.setAdapter(adapterLanguage);

Style.xml

<style name="SpinnerStyle" parent="android:style/Widget.ListView.DropDown">
    <item name="android:divider">@color/grey</item>
    <item name="android:dividerHeight">1dp</item>
</style>

Answer

iamreptar picture iamreptar · Feb 21, 2016

In your spinner:

android:overlapAnchor="false"

NOTE If you are supporting API below 21, this attribute has to be copy and pasted as it is available for API >= 21.