13

im looking for a turoial with source code on swipe gesutes, I dont want a view pager, I want a swipe gesture tutorial. here is one example I found but doesnt work for me

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

I would like something like this, thanks Please no view pagers

4

2 回答 2

11
    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);
    }
};
于 2012-08-06T18:11:33.190 回答
3

我会先在谷歌上搜索“Android 基本滑动手势”之类的内容。这就是我所做的,我最终得到了这个主题的热门帖子:在网格布局上进行手势检测

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

于 2012-08-06T18:08:02.503 回答