使用this mechanism我能够在ImageView中成功旋转图像。效果很好。
但是,如果ImageView具有背景图像,则该drawable也不会旋转。我怎样才能旋转ImageView的背景图像?
答案 0 :(得分:4)
覆盖draw()而不是onDraw()来旋转背景。
@Override
public void draw(Canvas canvas) {
canvas.save();
canvas.rotate(45,xRotation,yRotation);
super.draw(canvas);
canvas.restore();
}
答案 1 :(得分:2)
public class MainActivity extends Activity
{
private ImageView mImageView = null;
private Animation mRotateAnimation = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mImageView = (ImageView) findViewById(R.id.my_image);
mRotateAnimation = AnimationUtils.loadAnimation(this, R.anim.my_rotate_90);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mImageView.startAnimation(mRotateAnimation);
return true;
}
return super.onTouchEvent(event);
}
}