开发者

differentiating left and right scroll in gallery

开发者 https://www.devze.com 2023-03-31 03:27 出处:网络
Hie all , is there any method in android that can differentiate the left and the right scrolling actions in android.

Hie all , is there any method in android that can differentiate the left and the right scrolling actions in android.

differentiating left and right scroll in gallery

it is actually a customized gallery view so what I am trying to do is that on scroll actions i want to differen开发者_StackOverflow社区t images. I mean on left scroll I've different images and on right scroll I've different images to show. so i need to differentiate the let and right scroll.


Try this code:

new OnTouchListener() {

            @Override
            public boolean onTouch(View currentView, MotionEvent touchevent) {
                switch (touchevent.getAction())
                {
                case MotionEvent.ACTION_DOWN:
                {
                    oldTouchValue = touchevent.getX();
                    break;
                }
                case MotionEvent.ACTION_UP:
                {
                    float currentX = touchevent.getX();

                    if((oldTouchValue - currentX) < 50 && (oldTouchValue - currentX) > -50) {
                        return false;
                    }
                    if (oldTouchValue < currentX)
                    {
                        // Left swipe...
                    }
                    if (oldTouchValue > currentX)
                    {
                        // Right swipe
                    }
                    break;
                }
                }
                return false;
            }
        }
0

精彩评论

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