I have some layouts inside a scrollView. Those layouts have to be "swipable" in left and right directions but it creates some conflicts with the scrollView.
I've tried to disable the scrollView while touching on one of those layouts but in that case my scrollView is almost always disable.
This is how my layout looks like.
What I've now :
private void swipePositionsEvent() {
for(LinearLayout layout : layouts){
layout.setOnTouchListener(new OnSwipeTouchListener(this,
((ScrollView)findViewById(R.id.scroll_view_confirm_games))){
public void onSwipeRight() {
flipper.showNext();
}
public void onSwipeLeft() {
flipper.showPrevious();
}
});
}
In OnSwipeTouchListener:
Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// Disallow ScrollView to intercept touch events.
scrollView.requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
// Allow ScrollView to intercept touch events.
scrollView.requestDisallowInterceptTouchEvent(false);
break;
}
return gestureDetector.onTouchEvent(event);
}
Thank you!
Detect whether the first movement is horizontal or vertical before you disable the scrollview.