在刷卡方向的视图动画?

时间:2014-02-18 16:33:05

标签: android gesture-recognition

目前我已经成功完成了上述操作,在这三个区域中的每个区域进行扫描都将是一个XML动画,直到我离开屏幕为止,这是:

  1. 预先定义的路线,无论手指在哪里滑动,它都会完全笔直

  2. 中间和侧面滑动区域之间有滑动死区。

  3. 我正在寻找一种方法来改进滑动检测,方法是遵循实际的滑动方向并使动作更逼真?

    public abstract class OnUpDownGestureListener implements OnTouchListener {
    
        private Context context;
    
        private final GestureDetector gdt = new GestureDetector(this.context, new GestureListener());
    
        @Override
        public boolean onTouch(final View v, final MotionEvent event) {
            gdt.onTouchEvent(event);
            return true;
        }
    
        private final class GestureListener extends SimpleOnGestureListener {
    
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {
                click();
                return true;
            }
    
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    
                float x1 = e1.getX();
                float y1 = e1.getY();
    
                float x2 = e2.getX();
                float y2 = e2.getY();
    
                if (y1 - y2 > 120 && Math.abs(velocityY) > 200) {
                    onBottomToTop(); // Bottom to top
                } else if (y2 - y1 > 120 && Math.abs(velocityY) > 200) {
                    return false; // Top to bottom
                }
    
                /**
                 * bottom right to left top
                 */
                if (x1 - x2 > 120 && x1 > x2 && y1 - y2 > 120 && y1 > y2) {
                    onBottomRightToLeftTop();
    
                }
                /**
                 * left top corner to right
                 */
                else if (x2 - x1 > 120 && x2 > x1 && y2 - y1 > 120 && y2 > y1) {
                    // onTopLeftToBottomRight();
                }
                /**
                 * left bottom corner to right up
                 */
                else if (x2 - x1 > 120 && x2 > x1 && y1 - y2 > 120 && y1 > y2) {
                    onBottomLeftToRightTop();
                }
    
                /**
                 * Right corner to left bottom down
                 */
                else if (x1 > x2 && y2 > y1) {
                    onTopRightToBottomLeft();
                }
                return false;
            }
        }
    
        public abstract void click();
    
        public abstract void onBottomRightToLeftTop();
    
        public abstract void onTopLeftToBottomRight();
    
        public abstract void onTopRightToBottomLeft();
    
        public abstract void onBottomLeftToRightTop();
    
        public abstract void onBottomToTop();
    
    }
    

0 个答案:

没有答案