【发布时间】:2014-11-14 17:10:24
【问题描述】:
如何以枢轴为图像底部中心的模拟时钟的秒针制作动画(下面给出的图像链接)。
- 目前图像以中心为轴心旋转,但我需要轴心位于图像中红点指示的底部中心。我尝试设置 0.5,1.0 和 1.0,0.5,但图像移动到不同的区域并且没有在正确的点旋转。
- 在当前动画下秒针平滑扫动,如何实现类似于传统模拟时钟的停止和动画,停止和动画循环。
我正在使用的代码如下所示
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.image);
final Handler handler = new Handler();
calendar = Calendar.getInstance();
seconds = calendar.get(Calendar.SECOND);
seconds++;
handler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Log.i("Canvas", "second is " + seconds);
// imageView.animate()
// .setDuration(1000)
// .rotation(6f * seconds);
RotateAnimation rotateAnimation = new RotateAnimation(
(seconds - 1) * 6, seconds * 6,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setDuration(1000);
rotateAnimation.setFillAfter(true);
imageView.startAnimation(rotateAnimation);
handler.postDelayed(this, 1000);
seconds++;
}
}, 1000);
}
【问题讨论】: