Created
August 14, 2019 09:04
-
-
Save CodeK1988/ea0b023b91bd427cdff9573d66e3dbe6 to your computer and use it in GitHub Desktop.
VerticalOnlyNestedScrollView
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
| /** | |
| * thanks https://stackoverflow.com/questions/36093384/stop-nestedscrollview-inside-viewpager-to-process-horizontal-scrolls | |
| */ | |
| public class VerticalOnlyNestedScrollView extends NestedScrollView { | |
| public VerticalOnlyNestedScrollView(Context context) { | |
| super(context); | |
| } | |
| private float startX, startY; | |
| public VerticalOnlyNestedScrollView(Context context, AttributeSet attrs) { | |
| super(context, attrs); | |
| } | |
| public VerticalOnlyNestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) { | |
| super(context, attrs, defStyleAttr); | |
| } | |
| @Override | |
| public boolean onTouchEvent(MotionEvent ev) { | |
| if (!(ev.getAction() == MotionEvent.ACTION_DOWN) && ev.getHistorySize() > 0) { | |
| float yVector = ev.getY() - ev.getHistoricalY(0); | |
| float xVector = ev.getX() - ev.getHistoricalX(0); | |
| return Math.abs(yVector) + 100 <= Math.abs(xVector) || super.onTouchEvent(ev); | |
| } | |
| return super.onTouchEvent(ev); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment