Last active
August 29, 2015 14:16
-
-
Save XinyueZ/6c8538894cc4f54f4c41 to your computer and use it in GitHub Desktop.
A solution to scrolling-problem when the ScrollView mix with ScrollView or RecycleView or ListView etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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