Skip to content

Instantly share code, notes, and snippets.

@umarhussain15
Created August 30, 2017 11:04
Show Gist options
  • Save umarhussain15/b661ee44d196b1b6216fa6495b125343 to your computer and use it in GitHub Desktop.
Save umarhussain15/b661ee44d196b1b6216fa6495b125343 to your computer and use it in GitHub Desktop.
Android: Disabling Swipes on View Pager
<SwipeDisabledViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
public class SwipeDisabledViewPager extends ViewPager {
public SwipeDisabledViewPager(Context context) {
super(context);
}
public SwipeDisabledViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
// returning false will not propagate the swipe event
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment