如何通过滚动仅显示微调器中的前 3 个项目和其他项目?

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

所以我有一个微调器,你可以在图片中看到

所以我想做的是我只想显示前 3 个项目,其余项目应该是可滚动的。有任何想法吗?

您可以调整微调器弹出菜单的高度,如下所示:

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 中的微调器:

android:dropDownHeight="100dp"