2012-03-15 30 views
0

我想使用下面的代碼旋轉位圖。 (雖然無限旋轉有一個小滯後,但這是另一個故事),但是當在實際設備上測試旋轉是錯誤的(我認爲是錯誤的主軸)。仿真程序和設備之間的旋轉動畫漸變

我很感激任何幫助。

公共類CircleAnimation擴展視圖{

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); 

} 

}

回答

0

好吧,我發現這個問題。

我已經將最小SDK設置爲8,目標SDK也設置爲8。並且我在15測試。

將目標更改爲15並且它工作。

:P

ģ

+0

恭喜上的修補程序。如果可以,請將您的答案標記爲「已接受」,以幫助他人找到您的解決方案。乾杯〜 – 2012-03-16 17:48:52