public class MyinfoActivity extends Activity implements OnGestureListener { @OverrIDe public voID onCreate(Bundle savedInstanceState) { .......... .......... gestureScanner = new GestureDetector(this); resBlock = (tableRow) findVIEwByID(R.ID.ResBlock); gestureScanner = new GestureDetector(this); } @OverrIDe public boolean ontouchEvent(MotionEvent me){ Log.d(null,"touch"); if (gestureScanner.ontouchEvent(me)) return gestureScanner.ontouchEvent(me); else return false; } @OverrIDe public boolean onFling(MotionEvent e1,MotionEvent e2,float veLocityX,float veLocityY) { Log.d(null,"Fling"); ............ ............ } @OverrIDe public boolean onDown(MotionEvent arg0) { return false; } @OverrIDe public voID onLongPress(MotionEvent e) {} @OverrIDe public boolean onScroll(MotionEvent e1,float distanceX,float distanceY) { return false; } @OverrIDe public voID onShowPress(MotionEvent e) {} @OverrIDe public boolean onSingleTapUp(MotionEvent e) { return false; }}
它正在检测到touchEvent,但它并没有检测到任何甩动.我的代码有什么问题?
解决方法 我使用以下代码解决了这个问题.public class MyinfoActivity extends Activity { private GestureDetector gestureScanner; @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.myinfotrackerinner); gestureScanner = new GestureDetector(this,simpleOnGestureListener); } @OverrIDe public boolean ontouchEvent(MotionEvent event) { return gestureScanner.ontouchEvent(event); } GestureDetector.SimpleOnGestureListener simpleOnGestureListener = new GestureDetector.SimpleOnGestureListener() { @OverrIDe public boolean onDown(MotionEvent event) { return true; } @OverrIDe public boolean onFling(MotionEvent event1,MotionEvent event2,float veLocityY) { Log.d(null,"Fling"); int dx = (int) (event2.getX() - event1.getX()); // don't accept the fling if it's too short // as it may conflict with a button push if (Math.abs(dx) > MAJOR_MOVE && Math.abs(veLocityX) > Math.abs(veLocityY)) { if (veLocityX > 0) { moveGraph("L"); } else { moveGraph("R"); } return true; } else { return false; } } };}总结
以上是内存溢出为你收集整理的Android OnGestureListener Fling没有检测到全部内容,希望文章能够帮你解决Android OnGestureListener Fling没有检测到所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)