Skip to content

Instantly share code, notes, and snippets.

@XinyueZ

XinyueZ/mixscroll.java

Last active Aug 29, 2015
Embed
What would you like to do?
A solution to scrolling-problem when the ScrollView mix with ScrollView or RecycleView or ListView etc.
//Also been posted http://stackoverflow.com/a/28944297/1835650
//R.id.parent_view: The parent ScrollView.
//R.id.child_view: A scrollable object like RecycleView, ScrollView or ListView.
findViewById(R.id.parent_view).setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
View childV = findViewById(R.id.child_view);
if (childV != null) {
int[] l = new int[2];
childV.getLocationOnScreen(l);
RectF rect = new RectF(l[0], l[1], l[0] + childV.getWidth(), l[1] + childV.getHeight());
if(rect.contains( event.getX(), event.getY())) {
childV.getParent()
.requestDisallowInterceptTouchEvent(false);
childV.onTouchEvent(event);
return true;
}
}
childV.getParent()
.requestDisallowInterceptTouchEvent(true);
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment