Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spinner dropdown start from top of spinner

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>
like image 478
Kishore Jethava Avatar asked Dec 12 '15 09:12

Kishore Jethava


People also ask

How do you set a spinner to a specific position?

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.

What is the difference between ListView and spinner?

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.


2 Answers

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.

like image 119
iamreptar Avatar answered Oct 22 '22 03:10

iamreptar


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

like image 37
AliMola Avatar answered Oct 22 '22 03:10

AliMola