Spinning the spinner from the top of the spinner

The problem is that the Spinner drop-down list starts at the top line of Spinner, but it should start at the bottom line of Spinner

Normal condition

enter image description here

After pressing

enter image description here

Hide XML

 <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> 
+5
source share
2 answers

In your counter:

 android:overlapAnchor="false" 
+6
source

You can set these lines in your Spinner XML code:

 android:spinnerMode="dropdown" android:dropDownVerticalOffset="50dp" 

With this, your dropdownview will start at the top offset. You can copy the offset number or calculate it at runtime and use:

 setDropDownVerticalOffset(int pixels) 

More: Android Spinner

+6
source

Source: https://habr.com/ru/post/1237968/


All Articles