Android Click Through PopupWindow

前端 未结 2 1964
没有蜡笔的小新
没有蜡笔的小新 2021-01-02 07:19

I have created a class that extends popupwindow. its constructor looks something like the following

super(builder.context.get());

this.setWindowLayoutMode(V         


        
2条回答
  •  死守一世寂寞
    2021-01-02 07:51

    SOLUTION

    Register a touch interceptor for the Popupwindow. If you want the activity to handle it, assuming you have a reference to the activity, call someActivity.dispatchTouchEvent(someMotionEventPassedIntoTheTouchIntercepter);, if you want the popupwindow to handle the touch even, call someView.dispatchTouchEvent(theMotionEventPassedToTouchInterceptor) to the popupwindow's content view, as set in the popupwindows setContentView(someView) method.

    My method specifically looked like the following

    private OnTouchListener onTouchListener = new OnTouchListener() {
    @Override
        public boolean onTouch(View v, MotionEvent event) {
            float x = event.getX();
            float y = event.getY();
    
            if (Math.pow(x - coordinates[0], 2) + Math.pow((y - coordinates[1]), 2) < Math.pow(
                    radius, 2)) {
                activity.get().dispatchTouchEvent(event);
                return false;
            }
            frameLayout.dispatchTouchEvent(event);
            return true;
        }
    };
    

提交回复
热议问题