0

这是我的弹出窗口。但它正在处理任何触摸事件..

    popup = new PopupWindow(popupView, 300, 300, true);
    popup.showAsDropDown(v, -30, 0);
    popup.setBackgroundDrawable(getResources().getDrawable(R.drawable.background));
    popup.setOutsideTouchable(true);
    popup.setTouchable(true);
    popup.setFocusable(true);
    popup.setTouchInterceptor(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Log.d("TAG", "Touched in the window");
            return false;
        }
    });

请告诉我这段代码的问题..

4

1 回答 1

0

为了帮助偶然发现此线程的人...

而不是setTouchInterceptor(),我一直在使用setOnClickListener()or setOnTouchListener(),它们不是 PopupWindow 的成员,是的,但我只是调用 LayoutInflater 来获取弹出窗口(视图),然后将其设置为 PopupWindow 布局。继续使用 View 成员函数执行 MAGIC,因为它更适合您。

代码示例:

LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.my_popup_layout_id);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);


popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(popupWidth);
popup.setHeight(popupHeight);
//popup.setFocusable(true);
popup.setOutsideTouchable(false);


popup.showAsDropDown(anchorViewOfYourChoice, OFFSET_X, OFFSET_Y);
于 2013-05-07T17:03:08.307 回答