首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何降低安卓系统的下拉高度?

如何降低安卓系统的下拉高度?
EN

Stack Overflow用户
提问于 2020-08-14 21:07:53
回答 2查看 473关注 0票数 0

我在我的应用程序中使用默认的android微调器。当默认方法不起作用时,如何降低下拉列表的高度?

EN

回答 2

Stack Overflow用户

发布于 2020-08-14 21:17:03

检查此answer

代码语言:javascript
复制
 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
    android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(spinner);

    // Set popupWindow height to 500px
    popupWindow.setHeight(500);
}
catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) {
    // silently fail...
}
票数 0
EN

Stack Overflow用户

发布于 2020-08-14 21:15:39

通过使用Refelection,您可以设置下拉菜单的高度

代码语言:javascript
复制
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
        android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(spinner);

        // Set popupWindow height to 500px
        popupWindow.setHeight(500);
    }
    catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) {
        // silently fail...
    }

如果上面的方法不起作用,那么创建类扩展Spinner类,覆盖android.widget.PopupWindow用于计算的getWindowVisibleDisplayFrame(Rect outRect)。只需将outRect设置为限制显示下拉视图的区域即可。

代码语言:javascript
复制
@Override
public void getWindowVisibleDisplayFrame(Rect outRect) {
    WindowManager wm = (WindowManager) getContext.getSystemService(Context.WINDOW_SERVICE);
    Display d = wm.getDefaultDisplay();
    d.getRectSize(outRect);
    outRect.set(outRect.left, <STATUS BAR HEIGHT>, outRect.right, outRect.bottom);
}
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63413391

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档