开发者

PopupWindow with Gallery child

开发者 https://www.devze.com 2023-03-05 00:36 出处:网络
I\'m trying to use a PopupWindow with a Gallery inside, but when inflating the popup, I get the following error:

I'm trying to use a PopupWindow with a Gallery inside, but when inflating the popup, I get the following error:

ERROR/AndroidRuntime(31817): java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView

Does it mean there's no way to use a Gallery in a PopupWindow?

Thanks

btn_open_popup.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {

        LayoutInflater inflater = (LayoutInflater) HomeActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        View popup_container = inflater.inflate(R.layout.popup_container,null, false);

        final PopupWindow pw = new PopupWindow(popup_container, width, height, true);

        pw.showAtLocation(findViewById(R.id.home), Gravity.CENTER, 0,0);    

        ImageView btn_close_popup = (ImageView) popup_container.findViewById(R.id.btn_close_popup);
        btn_close_popup.setAlpha(120);

        btn_close_popup.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                pw.dismiss();
            }
        });
    }
});

popup_container.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="295dp"
    android:layout_height="307dp" android:background="@drawable/bg_popup">

    <ImageView android:id="@+id/btn_close_popup"
        android:开发者_C百科layout_width="25dp" android:layout_height="25dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true" android:src="#983742" />

    <Gallery android:id="@+id/popup_gallery"
        android:layout_width="fill_parent" android:layout_height="fill_parent">

        <ImageView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:background="@drawable/popup_contact" />
        <ImageView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:background="@drawable/popup_welcome" />
        <ImageView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:background="@drawable/popup_useraccount" />
        <ImageView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:background="@drawable/popup_geoloc" />

    </Gallery>

</RelativeLayout>


This doesn't necessarily answer your question, but why don't you use a dialog?. It's prettier and easier to use.

Edit 1: Yes you should be able to use a gallery in a popup window, I'm not sure why you can't get it to work.

0

精彩评论

暂无评论...
验证码 换一张
取 消