android 手势切换 activity

来源:互联网 发布:js点击链接弹出下拉框 编辑:程序博客网 时间:2024/06/05 16:57
public class OnGesterListenerIMP implements OnGestureListener {private ActivityTouchIntent callback;private boolean isIntentNext;public OnGesterListenerIMP(ActivityTouchIntent callback,boolean isIntentNext){this.callback=callback;this.isIntentNext=isIntentNext;}public boolean onDown(MotionEvent e) {// TODO Auto-generated method stubreturn false;}public void onShowPress(MotionEvent e) {// TODO Auto-generated method stub}public boolean onSingleTapUp(MotionEvent e) {// TODO Auto-generated method stubreturn false;}public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,float distanceY) {// TODO Auto-generated method stubreturn false;}public void onLongPress(MotionEvent e) {// TODO Auto-generated method stub}public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) {// TODO Auto-generated method stubif (e2.getX()-e1.getX()>200) {callback.callbackFinished();}if (Math.abs(e2.getX()-e1.getX())>200) {if(isIntentNext){callback.callbackIntentNext();}}return false;}public interface ActivityTouchIntent{void callbackIntentNext();void callbackFinished();}}

手势切换 (isIntentNext 是否需要进入下一个activity),注意:scrollview event事件获取不到需要dispatchTouchEvent重写(如果有listview 需要setTouchEvent..事件派发):

        @Overridepublic boolean dispatchTouchEvent(MotionEvent event) {// TODO Auto-generated method stubnew GestureDetector(this,new OnGesterListenerIMP(this, true)).onTouchEvent(event);return super.dispatchTouchEvent(event);}


0 0
原创粉丝点击