Last active
January 1, 2020 17:26
-
-
Save brandondenney/b8ddd655664eb295129d to your computer and use it in GitHub Desktop.
This file contains 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
package com.tumblr.widget; | |
import android.content.Context; | |
import android.util.AttributeSet; | |
import android.view.MotionEvent; | |
import android.widget.HorizontalScrollView; | |
/** | |
* {@link HorizontalScrollView} implementation that intercepts touch events from | |
* its parent so that it can be embedded in other horizontally scrolling view | |
* groups. | |
* | |
* @author brandon | |
* | |
*/ | |
public class InterceptingHorizontalScrollView extends HorizontalScrollView { | |
/** | |
* Constructor. | |
*/ | |
public InterceptingHorizontalScrollView(Context context) { | |
super(context); | |
} | |
/** | |
* Constructor. | |
*/ | |
public InterceptingHorizontalScrollView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
/** | |
* Constructor. | |
*/ | |
public InterceptingHorizontalScrollView(Context context, AttributeSet attrs, int defStyle) { | |
super(context, attrs, defStyle); | |
} | |
@Override | |
public boolean onInterceptTouchEvent(MotionEvent ev) { | |
if (getParent() != null) { | |
switch (ev.getAction()) { | |
case MotionEvent.ACTION_MOVE: | |
getParent().requestDisallowInterceptTouchEvent(true); | |
break; | |
case MotionEvent.ACTION_UP: | |
case MotionEvent.ACTION_CANCEL: | |
getParent().requestDisallowInterceptTouchEvent(false); | |
break; | |
} | |
} | |
return super.onInterceptTouchEvent(ev); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working perfectly! Thanks