import android.content.Context;import android.support.v4.view.ViewPager;import android.util.AttributeSet;import android.view.MotionEvent;import android.view.View;/** * 滑动页面工具类 * * Created by XiaobingLiu on 2016/10/21. */public class ViewPagerUtil extends ViewPager {    private boolean scrollble = true;   //是否可滑动    public ViewPagerUtil(Context context) {        super(context);    }    public ViewPagerUtil(Context context, AttributeSet attrs) {        super(context, attrs);    }    @Override    public boolean onTouchEvent(MotionEvent ev) {        if (!scrollble) {            return true;        }        return super.onTouchEvent(ev);    }    public boolean isScrollble() {        return scrollble;    }    /**     * 外部接口控制页面的滑动     * @param scrollble     */    public void setScrollble(boolean scrollble) {        this.scrollble = scrollble;    }    @Override    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)    {        super.onMeasure(widthMeasureSpec, heightMeasureSpec);        int childSize = getChildCount();        int maxHeight = 0;        for (int i = 0; i < childSize; i++)        {            View child = getChildAt(i);            child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));            if (child.getMeasuredHeight() > maxHeight)            {                maxHeight = child.getMeasuredHeight();            }        }        if (maxHeight > 0)        {            setMeasuredDimension(getMeasuredWidth(), maxHeight);        }    }

更多相关文章

  1. Android客户端WebService访问接口(Ksoap2Android调用.net服务端)
  2. android效果图之轮播
  3. RecycleView基本使用
  4. 使用Intent实现页面跳转 (另一种方法)
  5. Android(安卓)ProGuard打包混淆代码
  6. Android(安卓)ListView滑动回弹——overScrollBy
  7. 淘宝:模拟实现帮助提示页面
  8. Android触碰事件
  9. Android(安卓)滑动改变头部透明度

随机推荐

  1. Android应用程序组件Content Provider在
  2. Android(安卓)Asynchronous HTTPClient t
  3. android 横向滚动屏幕实现(3)
  4. 更改android spinner 背景
  5. Android(安卓)SearchView介绍及搜索提示
  6. android shape
  7. android xliff字符串操作
  8. Service Manager进程启动,睡眠等待在进程p
  9. Error:Could not find com.android.tools
  10. Android中话bitmap的简单示例