旋转模拟器和设备之间的动画不一致

时间:2012-03-15 10:44:54

标签: android

我正在尝试使用以下代码旋转位图。

代码在模拟器上工作正常(虽然无限旋转有一个小的延迟,但这是另一个故事)但是在实际设备上测试旋转是错误的(我认为错误的支点)。

我感谢任何帮助。

公共类CircleAnimation扩展了View {

Bitmap bitmap;
Paint paint;
RotateAnimation rotate;
AlphaAnimation blend;
ScaleAnimation scale;
AnimationSet spriteAnimation;

float centerX;
float centerY;
float offsetX;
float offsetY;

public CircleAnimation(Context context) {
      super(context);
      // TODO Auto-generated constructor stub

      bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tile);
        offsetX = bitmap.getWidth() / 2;
        offsetY = bitmap.getHeight() / 2;

        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setFilterBitmap(true);
}

@Override
protected void onDraw(Canvas canvas){
    //Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tile);
    //canvas.drawBitmap(myBitmap, 0, 0, null);
    super.onDraw(canvas);

    if (spriteAnimation == null) {
        centerX = canvas.getWidth() / 2;
        centerY = canvas.getHeight() / 2;
        createAnimation(canvas);
    }
    canvas.drawBitmap(bitmap, centerX - offsetX, centerY - offsetY, paint);
}

private void createAnimation(final Canvas canvas) {

    rotate = new RotateAnimation(0, 360, centerX, centerY);
    rotate.setRepeatCount(Animation.INFINITE);
    rotate.setInterpolator(new LinearInterpolator());
    rotate.setStartOffset(0);

    spriteAnimation = new AnimationSet(true);
    spriteAnimation.addAnimation(rotate);
    spriteAnimation.setDuration(1000);

    startAnimation(spriteAnimation);

}

}

1 个答案:

答案 0 :(得分:0)

好的,我发现了问题。

我已将最低SDK设置为8,并将SDK定位为8。我在15岁时进行测试。

将目标更改为15并且有效。

:P