速度或运动赛事的android加速 [英] speed or acceleration of motion event android

查看:233
本文介绍了速度或运动赛事的android加速的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能获得速度或Android的速度或触摸事件的加速与现有的API?我已经通过MotionEvent类了,没有在类中的字段似乎找回我需要的信息。任何帮助将大大AP preciated

Is it possible to get the speed or velocity or acceleration of touch event in android with the existing api? I have gone through MotionEvent class and none of the fields in that class seem to retrieve information that i need. Any help would be greatly appreciated

推荐答案

MotionEvent不帮你在这种情况下。您可以使用VelocityTracker类。它得到MotionEvent的实例,并计算最近触摸事件的速度。
你可以在这里看看它的文档:
<一href=\"http://developer.android.com/reference/android/view/VelocityTracker.html\">http://developer.android.com/reference/android/view/VelocityTracker.html

MotionEvent does not help you in this case. You can use VelocityTracker class. It gets MotionEvent instances and calculates velocity of recent touch events. You can take a look at its documentation here: http://developer.android.com/reference/android/view/VelocityTracker.html

首先,你必须得到一个实例获得通过()方法:

First you have to get an instance by obtain() method:

VelocityTracker velocity = VelocityTracker.obtain();

然后你可以添加ACTION_MOVE事件,它的队列:

then you can add ACTION_MOVE events to its queue:

    if(event.getAction() == MotionEvent.ACTION_MOVE)
    {
        velocity.addMovement(event);
    }

然后就可以计算出速度和提取x_velocity和y_velocity

then you can compute velocity and extract x_velocity and y_velocity

velocity.computeCurrentVelocity(1000);
float x_velocity = velocity.getXVelocity();
float y_velocity = velocity.getYVelocity();

我希望它为你工作。

I hope it works for you.

这篇关于速度或运动赛事的android加速的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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