Rotate an image around a pivot point

The question is simple: I want to rotate the image around a specific pivot point. Here is the code I'm using:

Matrix matrix = new Matrix(); matrix.setTranslate(bmpWidth/2, 0); matrix.preRotate(degrees, bmpWidth/2, 0); Bitmap resizedBitmap = Bitmap.createBitmap( bitmap, 0, 0, bmpWidth, bmpHeight, matrix, true); ImageView imageView = (ImageView) findViewById(R.id.bell); imageView.setImageBitmap(resizedBitmap); 

I get degrees of rotation from the accelerometer sensor. As a result, every time the image rotates around its center point,

+4
source share
2 answers

I think you should try:

 imageView.setPivotX(desiredXPivotPoint); imageView.setPivotY(desiredYPivotPoint); 

That should do the trick.

+6
source

This is kind of old, but there is a function that allows you to specify both the degree of rotation and the turning point:

  imageView.setRotation(degrees, px, py) 
+1
source

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


All Articles