Android: rotate the image in ImageView 90 degrees, but without delay

I am developing a game where the user needs to click on an image in ImageView to rotate it. In each image, the crane rotates 90 degrees clockwise. But the image takes time to turn from the old to a new position. This makes gameplay difficult. I 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 if there is another way to rotate the image without creating a delay .

+4
source share
4 answers

I also tried to do this once and did not find a solution other than using animation. Here is how I would do it.

 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); } 
+25
source

You do not need to rotate the object, just rotate it. If you are targeting API> = 11, you can always do this.

 mImageView.setRotation(angle); 

Greetings.

+10
source

Short method

View.animate().rotation(90).setDuration(0);

+3
source

Have you tried using a custom view that extends the image and rotates the image in the background thread?

-2
source

Source: https://habr.com/ru/post/1501603/


All Articles