Android PopupWindow监听点击外部事件

遇到一个需求,需要自己执行PopupWindow的显示和隐藏动画,但是PopupWindow点击外部区域时直接执行了dismiss事件,这样就没有我执行隐藏动画的机会,就想能不能阻断PopupWindow的dismiss事件,以下就是监听事件,判断不是PopupWindow内部区域的点击事件执行隐藏动画

popupWindow = new PopupWindow(popContentView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
popupWindow.setFocusable(true);
popupWindow.setTouchable(true);
ColorDrawable dw = new ColorDrawable(Color.TRANSPARENT);
popupWindow.setBackgroundDrawable(dw);
popupWindow.setOutsideTouchable(false);
popupWindow.setTouchInterceptor(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getY()>=0){//PopupWindow内部的事件
            return false;
        }
        if (isPopShowing) {
            isPopShowing=false;
            backgroundAlpha(false);
            PopupAnimateUtils.hideDownPopWindow(popupWindow, 300, popupWindow.getContentView().getHeight(), new Animator.AnimatorListener() {
                @Override
                public void onAnimationStart(Animator animation) {

                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    popupWindow.dismiss();
                }

                @Override
                public void onAnimationCancel(Animator animation) {

                }

                @Override
                public void onAnimationRepeat(Animator animation) {

                }
            });
        }
        return true;
    }
});

你可能感兴趣的:(Android效果)