Android 简单的 左右上下手势 判断

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

private float startx;
    private float starty;
    private float upoffset;
 
    @Override
    public boolean onTouchEvent(MotionEvent event) {
 
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            startx = event.getX();
            starty = event.getY();
            break;
        case MotionEvent.ACTION_MOVE:
            offset = (int) (event.getX() - startx) / 3;
            // Log.e("TAST", offset + "offset");
            if (Math.abs(offset) > 10) {
                Log.e("TAG", "Left and Right");
            }
            upoffset = event.getY() - starty;
            if (Math.abs(upoffset) > 20) {
                Log.e("TAG", "UP and Down");
            }
 
            invalidate();
 
        default:
            break;
        }
 
        return true;
    }