2

I want to use spinner in my Activity in android application.

My requirement is, I want to show only 6 items in drop down list at one time if their are more that 6 items then scroll bar should be visible. How to achieve this requirement.

Below is the sample code I am trying for UI in android activity.xml.

<Spinner
    android:id="@+id/spinner"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:spinnerMode="dropdown"
    android:dropDownVerticalOffset="40dp"
    android:forceHasOverlappingRendering="false" />
Kiran Maniya
  • 8,453
  • 9
  • 58
  • 81
Kandy
  • 29
  • 3
  • Possible duplicate of [Android limit the no of items displayed in a spinner's dropdown list](https://stackoverflow.com/questions/20238513/android-limit-the-no-of-items-displayed-in-a-spinners-dropdown-list) – Ricardo A. Sep 26 '19 at 19:12
  • 1
    Does this answer your question? [Can't make spinner's scrollbar always visible (Android)](https://stackoverflow.com/questions/10014485/cant-make-spinners-scrollbar-always-visible-android) – Sabito stands with Ukraine Nov 07 '20 at 01:04
  • Spinners in Android doesn't have a Scrollbar, the scrollbar exist within the listView maintained inside the Spinner, and has no public access. There's a run-time way to override it in the link below .. Resource: https://stackoverflow.com/a/12644532/2128327 – K_mns Nov 07 '20 at 01:03

2 Answers2

0

you can visit this link for more details How to limit the height of Spinner drop down view in Android

You can use this awesome library MaterialSpinner that will do all the hard work for you.

Download: implementation 'com.jaredrummler:material-spinner:1.3.1'

inside your xml file.

    <com.jaredrummler.materialspinner.MaterialSpinner
    android:id="@+id/spinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:ms_dropdown_max_height="400dp"/>

set height using app:ms_dropdown_max_height="400dp"

Aarushi
  • 3
  • 1
  • 4
-1

Add to your xml spinner element:

android:dropDownHeight="100dp"
JakeB
  • 2,043
  • 3
  • 12
  • 19
  • why is dropDownHeight unavailable to me? I can only use dropDownWidth, even that only programically and not in xml – new Apr 19 '21 at 20:48