How to implement swipe gesture in android

假装没事ソ 提交于 2019-11-30 20:11:35
Gabe Sechan

onTouchEvent is enough. What you want to do is:

  • Create a VelocityTracker and feed it the touch results from the view.
  • When you get a UP event, check what the velocity was. If its more than some threshold amount in the X direction, that counts as a swipe.
  • Start a new activity when you recognize it.

You'll likely have to play with the threshold a bit, otherwise a sloppy tap could be mistaken for a swipe.

If you want to swipe your view then you should use ViewFlipper You can set a onTouchListener on ViewFlipper. And you can register GestureDetector in onTouchListener. Here is one good example for that Android transitions- slide in and slide out.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!