Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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