Android Gesture手势操作(手势翻页效果)及幻灯片放映(2)

@Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        return this.detector.onTouchEvent(event);
    }
@Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        // TODO Auto-generated method stub
        if (e1.getX() - e2.getX() > 120) {
            this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,
                    R.drawable.left_in));
            this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
                    R.drawable.left_out));
            this.flipper.showNext();
            return true;
        } else if (e1.getX() - e2.getX() < -120) {
            this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,
                    R.drawable.right_in));
            this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
                    R.drawable.right_out));
            this.flipper.showPrevious();
            return true;
        } else if (e1.getY() - e2.getY() > 200) {
            this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,
                    R.drawable.push_up_in));
            this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
                    R.drawable.push_up_out));
            this.flipper.showNext();
            return true;
        } else if (e1.getY() - e2.getY() < -200) {
            this.flipper.setInAnimation(AnimationUtils.loadAnimation(this,
                    R.drawable.push_down_in));
            this.flipper.setOutAnimation(AnimationUtils.loadAnimation(this,
                    R.drawable.push_down_out));
            this.flipper.showPrevious();
            return true;
        }
        return false;
    }

重写两个事件,一个是onTouchEvent函数,一个是onFling函数

这样就可以实现翻页效果了。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wwxgyz.html