Android的手势是这样的开始屏幕上使用 [英] Android Gesture to that's used on the start screen

查看:79
本文介绍了Android的手势是这样的开始屏幕上使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么Android的API是用来获取滚动向左或Android上的启动画面?

What Android Api is used to get the scrolling to the left or to the right on the start screen on Android?

推荐答案

最简单的方法是通过检测一扔的手势。 Android的API有一个内置的探测器像丢,滚动,长期preSS,双击,双指缩放等基本手势。

The simplest way is by detecting a "Fling" gesture. The android API has a built in detector for basic gestures like flinging, scrolling, long press, double tap, pinch zoom, etc.

该文档可在 http://developer.android.com/reference /android/view/GestureDetector.html

你要做的就是创建GestureDetector的一个实例,覆盖视图的onTouchEvent方法你有兴趣检测手势和MotionEvent传递给GestureDetector。

What you do is create an instance of GestureDetector, override the onTouchEvent method of the view you are interested in detecting gestures for, and pass the MotionEvent to the GestureDetector.

您还必须提供一个OnGestureListener实现(最简单的延长SimpleOnGestureListener)的GestureDetector并且将处理所有动作的事件。

You also have to supply a OnGestureListener implementation (easiest to extend SimpleOnGestureListener) to the GestureDetector and that will handle all of your gesture events.

例如:

class MyView extends View
{
    GestureDetector mGestureDetect;

    public MyView(Context context)
    {
        super(context);
        mGestureDetect = new GestureDetector(new SimpleOnGestureListener()
        {

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) 
        {
        //check if the fling was in the direction you were interested in
        if(e1.getX() - e2.getX() > 0)
        {
        //Do something here
        }
        //fast enough?
        if(velocityX > 50)
        {
        //etc etc
        }

        return true;
        }
        }
    }

    public boolean onTouchEvent(MotionEvent ev)
    {
        mGestureDetector.onTocuhEvent(ev);
        return true;
    }
}

这篇关于Android的手势是这样的开始屏幕上使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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