I am developing a game where a user needs to tap on the image in ImageView to rotate it. On each tap image rotates by 90 degrees in clockwise direction. But image is taking time to rotate from old to new position. This is hampering the gameplay experience. I have used the following:
protected void onCreate(Bundle savedInstanceState)
{
...
...
imgview = (ImageView)findViewById(R.id.imageView1);
imgview.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap myImg = getBitmapFromDrawable(imgview.getDrawable());
Bitmap rotated = Bitmap.createBitmap(myImg,0,0,myImg.getWidth(),myImg.getHeight(),matrix,true);
imgview.setImageBitmap(rotated);
}
});
I want to know is there any other way to rotate the image without creating any delay in rotation.
I also tried to do it once and couldn't find any other solution but using animation. Here how I'd do.
private void rotate(float degree) {
final RotateAnimation rotateAnim = new RotateAnimation(0.0f, degree,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotateAnim.setDuration(0);
rotateAnim.setFillAfter(true);
imgview.startAnimation(rotateAnim);
}
You don't need to rotate the object, rotating the view should be enough. If you are aiming API>=11 you can always do this.
mImageView.setRotation(angle);
Cheers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With