Problem is Spinner
dropdown list start from top line of Spinner but it should be start from bottom line of Spinner
Normal state
After Click
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>
How do you set a spinner to a specific position? Code is as follows: Spinner spinner = new Spinner(this); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android. R. layout.
Spinners provide a quick way to select one value from a set. In the default state, a spinner shows its currently selected value. Touching the spinner displays a dropdown menu with all other available values, from which the user can select a new one. ListView is a view group that displays a list of scrollable items.
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.
You can to set this lines in your Spinner xml code:
android:spinnerMode="dropdown"
android:dropDownVerticalOffset="50dp"
With this, your dropdownview will start with top offset. You can hardcode the offset number or calculate it at runtime and use:
setDropDownVerticalOffset(int pixels)
More in: Android Spinner
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