Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android what should be pivot point to rotate image around its center of base

Please read the whole question carefully before marking duplicate or closing it

I want to rotate a image(specifically arrow image) around its center point of base.

e.g. At start my image will be like second hand in a clock on 9. And suppose if I rotate that image by 30 degree, it should look like clock second hand on 10 and if 120 degree the clock second hand on 1.

So I want to rotate that image around it's center(along x axis) of base.

So what should I pass as pivot(X & Y) if I first code

imageView.setPivotX(1f);
            imageView.setPivotY(1f);
            imageView.setRotation(-30);

or second code

Matrix matrix = new Matrix();
    imageView.setScaleType(ScaleType.MATRIX);
    matrix.postRotate((float) 20, 0f, 0f);
    imageView.setImageMatrix(matrix);

or third code

Bitmap myImg = BitmapFactory.decodeResource(getResources(), R.drawable.arrow_0_degree);
    Matrix matrix = new Matrix();
    matrix.postRotate(30);
    Bitmap rotated = Bitmap.createBitmap(myImg, 0, 1, myImg.getWidth(), myImg.getHeight(), matrix, true);
    imageView.setImageBitmap(rotated);

or fourth code

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);

Added an image for better understanding which rotated in 90 degrees along clockwise.

And I hope in future google will add more and clear documentation about the pivot points.

Thanks in advance.enter image description here

like image 225
Shirish Herwade Avatar asked Mar 26 '15 13:03

Shirish Herwade


People also ask

What is pivot rotation?

Rotation pivots let you rotate an object from a point other than its default pivot. When you rotate an object without adjusting its pivots, it rotates around itself. If you use the Pivots properties to offset the Rotation pivot for the object, you can define a new point from which you want the object to rotate.

How do I change the orientation of a picture on android?

Open your device's Settings app. . Select Accessibility. Select Auto-rotate screen.

Where should an anchor pivot point of the model reside?

By default, the pivot point of an object or group of objects/components is located at its center.


1 Answers

You were almost right with the fourth code ^^

You can achieve this like that :

    final RotateAnimation rotateAnim = new RotateAnimation(0.0f, 30,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f,
            RotateAnimation.RELATIVE_TO_SELF, 1f);
    rotateAnim.setDuration(0);
    rotateAnim.setFillAfter(true);
    mImageView.setAnimation(rotateAnim);
    rotateAnim.start();
like image 153
koni Avatar answered Sep 23 '22 10:09

koni