转:ViewPager禁止滑动

来源:互联网 发布:淘宝网店推广目标 编辑:程序博客网 时间:2024/05/17 03:22

原文出自 http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2015/0102/2254.html


  1. public class CustomViewPager extends ViewPager {
  2.  
  3.     private boolean isPagingEnabled = true;
  4.  
  5.     public CustomViewPager(Context context) {
  6.         super(context);
  7.     }
  8.  
  9.     public CustomViewPager(Context context, AttributeSet attrs) {
  10.         super(context, attrs);
  11.     }
  12.  
  13.     @Override
  14.     public boolean onTouchEvent(MotionEvent event) {
  15.         return this.isPagingEnabled && super.onTouchEvent(event);
  16.     }
  17.  
  18.     @Override
  19.     public boolean onInterceptTouchEvent(MotionEvent event) {
  20.         return this.isPagingEnabled && super.onInterceptTouchEvent(event);
  21.     }
  22.  
  23.     public void setPagingEnabled(boolean b) {
  24.         this.isPagingEnabled = b;
  25.     }}

0 0
原创粉丝点击