Question

On default if you swipe from left to right you scroll to the left, and vice versa.

But I want to invert this action. so if you swipe left to right the scrollview goes to the right. Is there a XML solution or do I have to do this in code?

Was it helpful?

Solution

I am pretty unsure about this but something along these lines:

  1. Intercept touch event
  2. Invert the X positions
  3. Dispatch the new inverted touch event

Code (not really):

HorizontalScrollView hsv;
hsv.setOnTouchListener(new OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        // TODO Auto-generated method stub
        event.setLocation(-1*event.getX(), event.getY());
        hsv.dispatchTouchEvent(ev);
        return true;
    }
})

OTHER TIPS

You could use a GestureDetector to listen for left/right swipes, implementing onScroll and/or onFling (probably both). This might work okay if you want to scroll the view by one contiguous item per gesture. You certainly could also implement continuous scrolling this way but I'd seriously consider whether this kind of interaction offers a good user experience. Usually on a touch device, the user would not expect scrolling to work this way around.

http://developer.android.com/training/gestures/detector.html http://developer.android.com/reference/android/view/GestureDetector.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top