1
如何使主轴位于图像的底部中心(下面给出的图像链接)来模拟模拟时钟的秒针。第二只手的动画制作
- 当前图像以中心为枢轴旋转,但我需要枢轴为图像中红点所指示的底部中心。我尝试设置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);
}