android-studio - android popupWindow 中宽度莫名很大,求帮助?

 二狗子 发布于 2022-11-02 18:56

这个是popupwindow的内容xml(就是放了个ListView):






展现popupwindow的时候,

public MenuPopup(final Context context) {
        **super(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);**
        View contentView = LayoutInflater.from(context).inflate(resId, null);
        ListView lv = (ListView) contentView
                .findViewById(R.id.lv_ppw_settings_lists);
        String[] menuItems = context.getResources().getStringArray(R.array.associator_query_menu);
        PopupSettingsAdapter adapter = new PopupSettingsAdapter(context, menuItems);
        ....
        }

我都用了wrap_content了
然而结果却是:

醉了,这是什么缘故。。。

3 个回答
  • 可能是ListView 的item的布局问题吧

    2022-11-05 01:52 回答
  • 。。用popupMenu吧。。那才是你想要的效果,并且比你这个简单美观多了

    2022-11-05 01:53 回答
  • 因为wrap_content对ListView是不起效的,没有明确的width hight,默认都是会撑满。

    2022-11-05 01:58 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有