当像facebook评论popupup那样触摸或向下触摸时如何关闭Popup对话框

时间:2015-01-15 14:09:14

标签: android dialog touch swipe popupwindow

我尝试在用户向上或向下移动时关闭弹出对话框,任何人都可以帮助我enter image description here

1 个答案:

答案 0 :(得分:0)

在课堂上使用它,

private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;

并粘贴此代码以检测向上和向下滑动,

class MyGestureDetector extends SimpleOnGestureListener {
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
        float velocityY) {
    try {
        if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH){
            return false;
        }

        if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE
                && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
            onUpSwipe(); // your method or code of your requirement
        } 

        else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE
                && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
            onDownSwipe(); // your method or code of your requirement
        }
    } catch (Exception e) {

    }
    return false;
  }
}