Answer the question
In order to leave comments, you need to log in
How to disable viewpager?
The situation is this, there are windows in the viewPager and in one of these windows you can run a fragment, and at the moment when the fragment is on the screen I need to disable the ability to scroll through the screens in the viewPager, how can I do this? Maybe there is some method in the viewPager that turns it off?
Answer the question
In order to leave comments, you need to log in
There is no easy way.
To prevent swipe from working, you need your own sub-class for ViewPager, with the following logic:
import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
public class TabItems extends ViewPager {
public boolean mIsEnabled;
public TabItems(Context context) {
super(context);
// TODO Auto-generated constructor stub
init();
}
public TabItems(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
void init() {
mIsEnabled = true;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (mIsEnabled) {
return super.onTouchEvent(event);
} else {
return false;
}
}
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (mIsEnabled) {
return super.onInterceptTouchEvent(event);
} else {
return false;
}
}
}
LinearLayout tabStrip = ((LinearLayout)tabLayout1.getChildAt(0));
for (int i = 0; i < tabStrip.getChildCount(); i++) {
tabStrip.getChildAt(i).setEnabled(false);
tabStrip.getChildAt(i).setAlpha(130);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question