如何实现在Android的滑动手势 [英] How to implement swipe gesture in android

查看:145
本文介绍了如何实现在Android的滑动手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的Andr​​oid。在这里,我想实现滑动手势活动之间导航。我用Google搜索了一下,发现在不同的地点不同的答案。但我无法得到确切的点。 通过阅读所有这些我认为我们需要实现的onTouchEvent() onFlingEvent()

I am new to Android. Here, I want to implement Swipe Gesture to navigate between Activities. I have googled it and found different answers in different sites. But I could not get the exact point. By reading all of them I got that we need to implement onTouchEvent() and onFlingEvent().

难道这些功能足以实现刷卡动作? 请具体说明如何进行分步实施轻扫手势。

Are these functions enough to implement the Swipe action? Please specify on How to proceed step wise to implement swipe gesture.

我很抱歉,如果我问你一个很简单的问题,因为我已经问过这个问题后,许多code段很长很长的尝试。

I am sorry if I asked you a very simple question as I have asked this question after a long long try of many code snippets.

任何一个可以请清除我的疑问?

Can any one please clear my doubt?

推荐答案

的onTouchEvent 就足够了。你要做的是:

onTouchEvent is enough. What you want to do is:

  • 创建一个 VelocityTracker 和饲料它 从视图触摸结果。
  • 当你得到一个UP事件,检查什么速度了。如果它的更多 比某阈值量在X方向上,则计为一 刷卡。
  • 在开始一个新的活动时,你认识吧。
  • 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.

这篇关于如何实现在Android的滑动手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆