android-studio - android popupWindow 中宽度莫名很大,求帮助?
迷茫
迷茫 2017-04-17 15:33:42
0
3
572

这个是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了
然而结果却是:

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

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
左手右手慢动作

Because wrap_content is not effective for ListView, if there is no clear width height, it will be full by default.

伊谢尔伦

. . Use popupMenu. . That’s the effect you want, and it’s much simpler and more beautiful than this one

阿神

Maybe it’s the layout problem of ListView’s items

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template