android-studio - android popupWindow 中宽度莫名很大,求帮助?
迷茫
迷茫 2017-04-17 15:33:42
[Android讨论组]

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/ppw_settings_normal"
android:orientation="vertical" >

<ListView
    android:id="@+id/lv_ppw_settings_lists"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:piderHeight="0dp"
    android:listSelector="@android:color/transparent" >
</ListView>

</LinearLayout>
展现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)
ringa_lee

因为wrap_content对ListView是不起效的,没有明确的width hight,默认都是会撑满。

伊谢尔伦

。。用popupMenu吧。。那才是你想要的效果,并且比你这个简单美观多了

阿神

可能是ListView 的item的布局问题吧

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号