Reputation: 471
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?
Upvotes: 1
Views: 4647
Reputation: 45942
I am pretty unsure about this but something along these lines:
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;
}
})
Upvotes: 2
Reputation: 1014
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
Upvotes: 0