开发者

Finger swipe in Android application

开发者 https://www.devze.com 2023-03-29 13:21 出处:网络
I have created an application where in I have a page which contains for text and one \'Next\' button and one \'Previous\' button. Clicking \'Next\' button, page shows some next text that is being take

I have created an application where in I have a page which contains for text and one 'Next' button and one 'Previous' button. Clicking 'Next' button, page shows some next text that is being takes from a list which contains a list of String text. 'Previous' button shows the last visited text.开发者_如何学运维

It is working fine. But now I want to implement something new where swipe of finger by user would take to the next text or previous. Finger swipe as used while accepting a call.


You are looking for gesture detectors. And you can find it here.

http://android-journey.blogspot.com/2010/01/android-gestures.html

http://coderzheaven.com/2011/03/using-gestures-in-androida-simple-example/

    @Override
    public boolean onTouchEvent(MotionEvent me) {
        return gestureScanner.onTouchEvent(me);
    }


    public boolean onDown(MotionEvent e) {
        viewA.setText("-" + "DOWN" + "-");
        return true;
    }

    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        viewA.setText("-" + "FLING" + "-");
        return true;
    }


    public void onLongPress(MotionEvent e) {
        viewA.setText("-" + "LONG PRESS" + "-");
    }


    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        viewA.setText("-" + "SCROLL" + "-");
        return true;
    }


    public void onShowPress(MotionEvent e) {
        viewA.setText("-" + "SHOW PRESS" + "-");
    }


    public boolean onSingleTapUp(MotionEvent e) {
        viewA.setText("-" + "SINGLE TAP UP" + "-");
        return true;
    }


Swipe to next view is the default behaviour for the Gallery class, you could start by giving this a try or extending it to meet your needs. Hope this helps!


Have a look at the GreenDroid project. It has a simple swipe view that can be easily customized. In particular, have a look at PagedView and examples on how to use it.

0

精彩评论

暂无评论...
验证码 换一张
取 消