0

我正在尝试imageViewsrotateAnimation. 我计算每 30 毫秒旋转的度数。如果角度发生变化,我创建旋转动画:

rpmAnim=new RotateAnimation((float)Rpmcurrentdegree, (float)Rpmdegree, ivNadel.getWidth()/2, ivNadel.getHeight()/2);
rpmAnim.setFillEnabled(true);
rpmAnim.setFillAfter(true);

...然后我开始 imageView 的动画:

 ivNadel.startAnimation(rpmAnim);

旋转工作正常,但是当度数没有改变时,它会跳回到起始位置。有谁知道为什么?

4

1 回答 1

0

set the setAnimationListener on rpmAnim:

rpmAnim.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationEnd(Animation arg0) {

          // here rotate the image

        }

        @Override
        public void onAnimationRepeat(Animation animation) {}
        @Override
        public void onAnimationStart(Animation animation) {}
    });

to rotate the image you can

  1. extends ImageView in order to create your custom image view
  2. override onDraw
  3. set your rotation angle
  4. invalidate your custom image view

the overridden onDraw could look like:

 protected void onDraw(Canvas canvas) {
     canvas.save()
     canvas.rotate(your rotation angle...)
     super.onDraw(canvas)
     canvas.restore()
 }
于 2012-05-02T09:41:44.230 回答