简体   繁体   中英

how to only display First 3 items in a spinner and other items by scrolling?

So i have a spinner as you can see in the image

微调图像

So what i want to do is that i only want to display the first 3 items and rest items should be scroll-able. Any Ideas?

you can adjust you spinner popup menu height like below:

Spinner spinner = (Spinner) findViewById(R.id.spinner);
    try {
        Field popup = Spinner.class.getDeclaredField("mPopup");
        popup.setAccessible(true);

        // Get private mPopup member variable and try cast to ListPopupWindow
        ListPopupWindow popupWindow = (ListPopupWindow) popup.get(spinner);
        popupWindow.setHeight(500);
    }
    catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) {
        // silently fail...
    }

xml 中将此属性设置为 spinner :

android:dropDownHeight="100dp"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM