Another simple way to rotate an ImageView
:
UPDATE:
Required imports:
import android.graphics.Matrix;
import android.widget.ImageView;
Code: (Assuming imageView
, angle
, pivotX
& pivotY
are already defined)
Matrix matrix = new Matrix();
imageView.setScaleType(ImageView.ScaleType.MATRIX); //required
matrix.postRotate((float) angle, pivotX, pivotY);
imageView.setImageMatrix(matrix);
This method does not require creating a new bitmap each time.
NOTE: To rotate an ImageView
on ontouch at runtime you can
set onTouchListener on ImageView
& rotate it by adding last two
lines(i.e. postRotate matrix & set it on imageView) in above code
section in your touch listener ACTION_MOVE part.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…