就是说这个类可以为按钮或者背景等提供渐变颜色的绘制。
TextPaint的概述:
TextPaint is an extension of Paint that leaves room for some extra data used during text measuring and drawing.
TextPaint是Paint类的一个扩展,主要是用于文本在绘制的过程中为附件的数据留出空间。
GestureDetector:手势检测,看下开发文档中关于该类的概述:
Detects various gestures and events using the supplied MotionEvents. The GestureDetector.OnGestureListener callback will notify users when a particular motion event has occurred. This class should only be used with MotionEvents reported via touch (don't use for trackball events).
为各种手势和事件提供MotionEvents。当一个具体的事件发生时会调用回调函数GestureDetector.OnGestureListener。这个类应该只适用于MotionEvents通过触摸触发的事件(不要使用追踪事件)。
140行到156行是构造方法,175到183行是set和getAdapter。在193行,setInterpolator()方法,设置interPolator这个动画接口,我们看下这个接口的概述:
An interpolator defines the rate of change of an animation. This allows the basic animation effects (alpha, scale, translate, rotate) to be accelerated, decelerated, repeated, etc.
定义了一种基于变率的一个动画。这使得基本的动画效果(alpha, scale, translate, rotate)是加速,减慢,重复等。这个方法在随机数这个例子中被使用。
203行到213行设置显示的item条数。在setVisibleItems()方法里面调用了View的invalidate()方法,看下文档中对该方法的介绍:
Invalidate the whole view. If the view is visible, onDraw(Android.graphics.Canvas) will be called at some point in the future. This must be called from a UI thread. To call from a non-UI thread, call postInvalidate().
使全部视图失效,如果View视图是可见的,会在UI线程里面从新调用onDraw()方法。
223行到233行是设置Label,既后面图片中的hours.
245行到296行是设置监听,在上面已经简单的说了一下,这里不在累述。
307行到349行是设置正被选中item,就是在那个阴影条框下的那个部分,比较简单。里面主要调用了scroll这个方法:
- /**
- * Scroll the wheel
- * @param itemsToSkip items to scroll
- * @param time scrolling duration
- */
- public void scroll(int itemsToScroll, int time) {
- scroller.forceFinished(true);
- lastScrollY = scrollingOffset;
- int offset = itemsToScroll * getItemHeight();
- scroller.startScroll(0, lastScrollY, 0, offset - lastScrollY, time);
- setNextMessage(MESSAGE_SCROLL);
- startScrolling();
- }
357行到365行是设置item数据能否循环使用。
384行的initResourcesIfNecessary()方法,从字面意思,如果需要的初始化资源。
- private void initResourcesIfNecessary() {
- if (itemsPaint == null) {
这个方法就是初始化在532行calculateLayoutWidth()方法中调用了这个方法,同时调用了487行的getMaxTextLength()这个方法。
471行getTextItem(int index)通过一个索引获取该item的文本。
这是第一部分,没有多少有太多意思的地方,重点的地方在以后532行到940行的内容,另起一篇,开始分析,这一篇先到这。
最后是下载地址:
免费下载地址在 http://linux.linuxidc.com/
用户名与密码都是www.linuxidc.com
具体下载目录在 /2012年资料/6月/18日/Android仿iPhone滚轮控件实现及源码分析/
