简单的滑动手势到活动教程?

时间:2012-08-06 18:02:24

标签: android eclipse layout swipe swipe-gesture

我正在寻找一个带滑动gesute源代码的turoial,我不想要一个视图寻呼机,我想要一个轻扫手势教程。 这是我找到的一个例子,但对我不起作用

http://www.eridem.net/android-tip-010-left-and-right-swipe-gesture-events

我想要这样的东西,谢谢 请不要查看寻呼机

2 个答案:

答案 0 :(得分:10)

    SimpleOnGestureListener mySimpleGestureListener = new SimpleOnGestureListener()
 {

    @Override
    public boolean onDoubleTap(MotionEvent e) { 
        Logout.debug("onDoubleTap");
        return super.onDoubleTap(e);
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) 
    {
        String velocity="onFling: \n" + e1.toString() + "\n" + e2.toString() +"\n"
                + "velocityX= " + String.valueOf(velocityX) + "\n"
                + "velocityY= " + String.valueOf(velocityY) + "\n";
        Logout.debug("onFling velocity="+velocity);
                    return super.onFling(e1, e2, velocityX, velocityY);
    }

    @Override
    public void onLongPress(MotionEvent e) {
        Logout.debug("onLongPress: \n" + e.toString());
        super.onLongPress(e);
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        Logout.debug("onSingleTapConfirmed: \n" + e.toString());
        return super.onSingleTapConfirmed(e);
    }

    private boolean permissibleYVelocity(float velocityY)
    {
        if ((velocityY < -200) || (velocityY > 200))
        {
            return false;
        }
        else
        {
            return true;
        }

    }
};

GestureDetector myGestureDetector = new GestureDetector(mSimpleOnGestureListener);

View.OnTouchListener mOnListTouchListener = new  OnTouchListener()
{
    @Override
    public boolean onTouch(View view, MotionEvent event)
    {
        Logout.debug("list onTouch()");
         return myGestureDetector.onTouchEvent(event);
    }
};

答案 1 :(得分:3)

我会先搜索“Android基本滑动手势”之类的内容。这就是我所做的,我最终得到了关于这个主题的人们发帖:Fling gesture detection on grid layout

首先点击谷歌是:http://pcfandroid.wordpress.com/2011/07/17/swipe-with-android-android-tutorial/,也适用于你的问题