javaandroidgraphicscanvas

Android Rotatable ImageView


I am trying to create a Rotatable an ImageView to which I will specify certain angle and pivot point and see it rotated around that pivot point. I tried something like this:

Matrix matrix = new Matrix();
matrix.postRotate(45, imageView.getWidth(), imageView.getHeight());
imageView.setScaleType(ScaleType.MATRIX);
imageView.setImageMatrix(matrix);

but the parameters of postRotate method (the second and third - the pivot points) make NO CHANGE at all. even if they are 0, 0 - it's the same thing.

So I wanna create a ImageView that would be rotated by certain angle when initialized. In this example 45 degrees. I tried setting the bounds and staff.. no help.

How do I do that? :/


Solution

  • You can rotate a ImageView by using setRotation(int);

    // rotate imageView 45 around center pivot point
    imageView.setPivotX(imageView.getWidth()/2);
    imageView.setPivotY(imageView.getHeight()/2);
    imageView.setRotation(45);
    

    Reference: http://developer.android.com/reference/android/view/View.html#setRotation(float)