0
아래 코드를 사용하여 비트 맵을 회전하려고합니다.에뮬레이터와 장치 사이의 RotationAnimation 불일치
코드는 에뮬레이터에서 잘 작동하지만 (무한 회전에는 작은 지연이 있지만 다른 이야기이기는하지만) 실제 장치에서 테스트 할 때 회전이 잘못되었습니다 (잘못 생각한 것 같습니다).
감사합니다.
G
공용 클래스 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);
}
}
축하. 가능한 경우 다른 사람들이 귀하의 솔루션을 찾을 수 있도록 답변을 '수락'으로 표시하십시오. 건배 ~ –