zoukankan      html  css  js  c++  java
  • 自定义ViewPager控制是否滑动

    package com.lvshandian.menshen.view;

    /**
    * Created by zhang on 2016/11/8.
    * 创建自定义滑动,禁止滑动的ViewPager
    */

    import android.content.Context;
    import android.support.v4.view.ViewPager;
    import android.util.AttributeSet;
    import android.view.MotionEvent;

    public class MyViewPager extends ViewPager {
    //设置是否滑动
    private boolean isCanScroll = true;

    public MyViewPager(Context context, AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
    }

    public MyViewPager(Context context) {
    super(context);
    // TODO Auto-generated constructor stub
    }
        //设置是否滑动
    public void setCanScroll(boolean isCanScroll) {
    this.isCanScroll = isCanScroll;
    }

    @Override
    public boolean onTouchEvent(MotionEvent arg0) {
    // TODO Auto-generated method stub
    if (isCanScroll) {
    return super.onTouchEvent(arg0);
    } else {
    return false;
    }
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent arg0) {
    // TODO Auto-generated method stub
    if (isCanScroll) {
    return super.onInterceptTouchEvent(arg0);
    } else {
    return false;
    }

    }

    @Override
    public void setCurrentItem(int item, boolean smoothScroll) {
    // TODO Auto-generated method stub
    super.setCurrentItem(item, smoothScroll);
    }

    @Override
    public void setCurrentItem(int item) {
    // TODO Auto-generated method stub
    super.setCurrentItem(item, false);
    }
    }
  • 相关阅读:
    css之深入理解padding
    css布局大杂烩
    css深入理解margin
    css之深入理解border
    css样式画各种图形
    css Sprite雪碧图
    JVM,JRE,JDK
    JAVA 遍历数组
    JAVA 得到数组的长度
    大一对软件工程
  • 原文地址:https://www.cnblogs.com/huihuizhang/p/6043378.html
Copyright © 2011-2022 走看看