Her*_*t74 2 android android-viewpager
我可以通过扩展ViewPager来禁用ViewPager以使用setPagingEnabled方法,但现在我只是想暂时禁用一个子节点.
我怀疑我必须通过访问ViewPager的setScrollState方法来覆盖OnPageScrolled并取消滚动,但我无法弄清楚如何.
多数民众赞成我的解决方案:
public class NonSwipeableViewPager extends ViewPager {
private boolean swipe = true;
public boolean isSwipe() {
return swipe;
}
public void setSwipe(boolean swipe) {
this.swipe = swipe;
}
public NonSwipeableViewPager(Context context) {
super(context);
}
public NonSwipeableViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent arg0) {
if (swipe) {
return super.onInterceptTouchEvent(arg0);
}
// Never allow swiping to switch between pages
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6802 次 |
| 最近记录: |