如何在另一个PopupWindow上设置PopupWindow

时间:2017-02-13 06:25:45

标签: java android popupwindow

我的应用程序中有两个PopupWindows,它们相交。现在我想管理另一个PopupWindow上显示的PopupWindow,它意味着Z轴。有什么想法吗? 你可以看到以下图片。

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

首先是PopupWindow,然后在这个PopupWindow上单击TextView,然后显示第二个PopupWindow。

PopupWindow mPop,mPop2;

    /**
     * show first popupWindow
     */
    private void popupWindow(final View vi) {
        View view = LayoutInflater.from(this).inflate(R.layout.pop, null);
        TextView tv = (TextView) view.findViewById(R.id.tv1);
        //click show second one
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupWindow2(vi);
            }
        });
        if (null == mPop) {
            mPop = new PopupWindow(view);
        }
        mPop.setHeight(294);
        mPop.setWidth(200);
        mPop.setFocusable(true);
        mPop.setOutsideTouchable(true);
        mPop.setBackgroundDrawable(new ColorDrawable(0));
        mPop.showAtLocation(vi, Gravity.CENTER | Gravity.CENTER, 22,
                22);
        mPop.update();

    }

/**
    * show second popupWindow
    */
    private void popupWindow2(View v) {
        View view = LayoutInflater.from(this).inflate(R.layout.pop2, null);
        if (null == mPop2) {
            mPop2 = new PopupWindow(view);
        }
        mPop2.setHeight(294);
        mPop2.setWidth(200);
        mPop2.setFocusable(true);
        mPop2.setOutsideTouchable(true);
        mPop2.setBackgroundDrawable(new ColorDrawable(0));
        mPop2.showAtLocation(v, Gravity.CENTER | Gravity.CENTER, 42,
                42);
        mPop2.update();

    }

并解决了这个问题。试一试。 sample

相关问题