Android开源中国客户端学习 (自定义View)左右滑动控件ScrollLayout <11>
左右滑动的控件我们使用的也是非常多了,但是基本上都是使用的viewpager 等 android基础的控件,那么我们有么有考虑过查看他的源码进行定制呢?当然,如果你自我感觉非常好的话可以自己定制一个,osc的ScrollLayout就是自己定义的View 和Viewpager的区别还是不小的 代码不是很多不到300行,但是却实现了左右滑动页面的效果,还是值得学习的.效果如下: 我们看到ScrollLayout直接继承了ViewGroup然后自定义了一系列功能,那么接下来就分析一下: 我们知道ViewGroup的绘制流程基本分为onMeasure ,onLayout ,onDraw三部分 那么就首先看onMeasure @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { //Log.e(TAG, "onMeasure"); super.onMeasure(widthMeasureSpec, heightMeasureSpec); final int width = MeasureSpec.getSize(widthMeasureSpec); final int widthMode = MeasureSpec.getMode(widthMeasureSpec); if