Android 设置秒针动画
如何设置模拟时钟秒针的动画,枢轴是图像的底部中心(下面给出了图像链接)Android 设置秒针动画,android,animation,Android,Animation,如何设置模拟时钟秒针的动画,枢轴是图像的底部中心(下面给出了图像链接) 目前,图像以中心为轴心旋转,但我需要轴心是图像中红色圆点指示的底部中心。我尝试设置0.5,1.0和1.0,0.5,但图像移动到另一个区域,并且没有在正确的点上旋转 随着当前动画秒手扫顺利,如何实现停止和动画,停止和动画周期类似于传统的模拟时钟 下面给出了我正在使用的代码 protected void onCreate(Bundle savedInstanceState) { super.onCreate(saved
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);
}
秒针的长度大约等于圆的半径或圆直径的一半。你的第二只手的旋转原点必须是该圆的中心。将圆的中心放置在零x y原点。将第二只手的底部放在零原点上。旋转是相对于圆心的。当我使用0.5f和1.0f作为旋转轴时,它起作用了。所需的更改是ImageView的高度和宽度应该是固定的。早些时候,它被设置为包装这两个项目的内容。这导致图像在旋转之前发生移动
RotateAnimation rotateAnimation = new RotateAnimation(
(seconds - 1) * 6, seconds * 6,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 1f);