博文也是个纠结的事情。。。。好吧,不浪费时间吐糟了,速战速决吧。。。。
这次的时钟,用的就是补间动画,而且还只用到了一个属性,就是rotate。
我直接写在布局文件里了。
看一下rotate的几个参数:
<rotate
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="0" //开始旋转的位置
android:toDegrees="+360" //结束旋转的位置
android:pivotX="0%" //旋转中心X坐标
android:pivotY="0%" //旋转中心Y坐标
android:duration="60000" //毫秒为单位的持续时间
android:repeatCount="-1" //无限循环
/>
然后把定义在xml中的动画应用在一个ImageView上,在.java中实现动画,代码如下:
ImageView Myclock = (ImageView)findViewById(R.id.Myclock);
ImageView second = (ImageView)findViewById(R.id.second);
ImageView minute = (ImageView)findViewById(R.id.minute);
ImageView hour = (ImageView)findViewById(R.id.hour);
Animation anisecond = AnimationUtils.loadAnimation(MyclockActivity.this, R.anim.second);
Animation animinute = AnimationUtils.loadAnimation(MyclockActivity.this, R.anim.minute);
Animation anihour = AnimationUtils.loadAnimation(MyclockActivity.this, R.anim.hour);
second.startAnimation(anisecond);
minute.startAnimation(animinute);
hour.startAnimation(anihour);
然后就是大家都有提到的匀速旋转问题。。。百度里好多这样的问题,所以一百度就得到了答案。。。在.java中加入代码:
LinearInterpolator lir = new LinearInterpolator();
animationRotate.setInterpolator(lir);
可以实现指针的匀速运转。
关键的说的差不多了。。。。最后贴图。。。。
![](http://hi.csdn.net/attachment/201111/18/0_1321618053MMXE.gif)