Skip to content

Instantly share code, notes, and snippets.

@brandondenney
Last active January 1, 2020 17:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brandondenney/b8ddd655664eb295129d to your computer and use it in GitHub Desktop.
Save brandondenney/b8ddd655664eb295129d to your computer and use it in GitHub Desktop.
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);
}
}
@buzeeg
Copy link

buzeeg commented Nov 18, 2013

Working perfectly! Thanks

@victorelli17
Copy link

It works for me, thanks a lot!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment