Answer the question
In order to leave comments, you need to log in
Is it possible to disable swipe in fragments?
Hello.
Is it possible to disable swipe in fragments?
Thank you.
Answer the question
In order to leave comments, you need to log in
We write our ViewPager:
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
public class NoSwipeViewPager extends ViewPager{
private boolean swipeable;
public NoSwipeViewPager(Context context) {
super(context);
}
public NoSwipeViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.swipeable = true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (this.swipeable) {
return super.onTouchEvent(event);
}
return false;
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (this.swipeable) {
return super.onInterceptTouchEvent(event);
}
return false;
}
public void setSwipeable(boolean swipeable) {
this.swipeable = swipeable;
}
}
<com.example......NoSwipeViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
private NoSwipeViewPager mViewPager;
..............
mViewPager = (NoSwipeViewPager) findViewById(R.id.container);
mViewPager.setSwipeable(false);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question