How to position all images rotating in center point - android

How to place all five images in center white rotating clock wise and anti-clock wise at center point. I tried, but im getting like this ( below image) As of now, it is not rotating at center point.

Here is my code.

public class StartRotatingActivity extends AppCompatActivity implements     Animation.AnimationListener {
private Context mContext;
private ImageView timeBackground_1, timeBackground_2, timeBackground_3, timeBackground_4, timeBackground_5;
Animation animationRight, animationLeft;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_start);
    if (getSupportActionBar() != null)
        getSupportActionBar().hide();

    mContext = this;
    timeBackground_1 = (ImageView) findViewById(R.id.bgTimer1);
    timeBackground_2 = (ImageView) findViewById(R.id.bgTimer2);
    timeBackground_3 = (ImageView) findViewById(R.id.bgTimer3);
    timeBackground_4 = (ImageView) findViewById(R.id.bgTimer4);
    timeBackground_5 = (ImageView) findViewById(R.id.bgTimer5);

    animationRight = AnimationUtils.loadAnimation(this, R.anim.rotate_right);
    animationRight.setDuration(12000);
    animationLeft = AnimationUtils.loadAnimation(this, R.anim.rotate_left);
    animationLeft.setDuration(12000);

    timeBackground_1.startAnimation(animationRight);
    timeBackground_2.startAnimation(animationLeft);
    timeBackground_3.startAnimation(animationRight);
    timeBackground_4.startAnimation(animationLeft);
    timeBackground_5.startAnimation(animationRight);

}

@Override
public void onAnimationStart(Animation animation) {

}

@Override
public void onAnimationEnd(Animation animation) {

}

@Override
public void onAnimationRepeat(Animation animation) {

}
}

startActivity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:gravity="center"
android:orientation="vertical">

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center">

    <ImageView
        android:id="@+id/bgTimer1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        app:srcCompat="@mipmap/bg_time_1" />

    <ImageView
        android:id="@+id/bgTimer2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        app:srcCompat="@mipmap/bg_time_2" />

    <ImageView
        android:id="@+id/bgTimer3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        app:srcCompat="@mipmap/bg_time_3" />

    <ImageView
        android:id="@+id/bgTimer4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        app:srcCompat="@mipmap/bg_time_4" />

    <ImageView
        android:id="@+id/bgTimer5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        app:srcCompat="@mipmap/bg_time_5" />
</FrameLayout>
</LinearLayout>

Rorateleft.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:toDegrees="360" />

Rotateright.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:toDegrees="0" />

Thanks for advance.

Use object animation. Set animation as below.

ObjectAnimator one = ObjectAnimator.ofFloat(timeBackground_1 ,
                "rotation", 0f, 360f);
        one.setDuration(5000);
        one.setRepeatCount(-1);
        one.start();

        ObjectAnimator two = ObjectAnimator.ofFloat(timeBackground_2 ,
                "rotation", 360f, 0f);
        two.setDuration(5000);
        two.setRepeatCount(-1);
        two.start();

        ObjectAnimator three = ObjectAnimator.ofFloat(timeBackground_3 ,
                "rotation", 0f, 360f);
        three.setDuration(5000);
        three.setRepeatCount(-1);
        three.start();

        ObjectAnimator four = ObjectAnimator.ofFloat(timeBackground_4 ,
                "rotation", 360f, 0f);
        four.setDuration(5000);
        four.setRepeatCount(-1);
        four.start();

        ObjectAnimator five = ObjectAnimator.ofFloat(timeBackground_5 ,
                "rotation", 0f, 360f);
        five.setDuration(5000);
        five.setRepeatCount(-1);
        five.start();

Android: How to rotate a bitmap on a center point, getCenterX() is basically the bitmaps X position + the bitmaps width / 2) Now all the bitmaps rotate properly but it is not without some minor  When you press the Rotate button, each of the images is rotated around its center, while maintaining its position in the center of the region on the screen. The Scale button resizes the images.

Problems are in your pivots in Rotateleft.xml

android:pivotX="70%"
android:pivotY="30%"

make them :

android:pivotX="50%"
android:pivotY="50%"

You could also try it in code:

Animation a = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        a.setRepeatCount(Animation.INFINITE);
        a.setDuration(12000);

How can I correct upside down and sideways photos?, Help CenterCommunityCan't find your photos? On your Android device, open the Google Photos app Photos . To crop or rotate, tap Crop & rotate Crop & rotate . broken now and I have no idea who to call or what to do about it but all my recent pictures are upside down or sideways. Unable to mark. Android: How to rotate a bitmap on a center point (6) I've been looking for over a day for a solution to this problem but nothing helps, even the answers here. Documentation doesn't explain anything too. I am simply trying to get a rotation in the direction of another object.

Oh, it's really easy to move imageView over the other (bottom) view's center:

rotate_anim.xml: (please notice pivot params)

<set
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false">
     <rotate
        android:fromDegrees="0"
        android:toDegrees="90"
        android:pivotX="50%"
        android:pivotY="100%"
        android:duration="1000" />
</set>

And in your activity:

(kotlin):

val an = AnimationUtils.loadAnimation(this, R.anim.rotate_anim)
an.fillAfter = true
sector.startAnimation(an)

(java):

Animation an = AnimationUtils.loadAnimation(this, R.anim.rotate_anim);
an.fillAfter = true
sector.startAnimation(an)

html5-canvas, html5-canvas Rotate an Image or Path around it's centerpoint you can undo the effects of steps#1-3 by resetting all transformations to their default state android.graphics.Matrix provide below methods to process images. setRotate(float degree) : Rotate image for angle degree. Axis is (0, 0). setRotate(float degree,float x,float y) : Similar with setRotate(float degree), but axis is (x, y). setScale(float scaleX,float scaleY) : Scale image,

Camera and View | Maps SDK for Android, The maps in the Maps SDK for Android can be tilted and rotated with easy The first image shows a schematic of this; position 1 is the camera position, and at the map's center point, but now the area represented by the line at position 4 is now camera's latitude, longitude and zoom, while preserving all other properties. 1. Draw a ray from the center of rotation to the point you wish to rotate. 2. Draw an angle with the center of rotation as the vertex. 3. Use a compass to draw a circle (arc) with the center at the center of rotation and a radius from the center of rotation to the point you are rotating. 4. Now rotate all the other points and connect the dots.

Resize, move, and rotate clips in Final Cut Pro, White circle in the center: Shows the rotation anchor point. Drag anywhere inside the image to adjust the image's position. Blue handle extending from the center  3 Rotation on a specific layer. Select the layer you want to rotate and go to the menu and click on ‘Layer’ – ‘Rotation’ and select a rotation method of your choice. In this example, the layer with the cat on it will be rotated. Flip Vertically

Determining rotations (article) | Rotations, There are two properties of every rotation—the center and the angle. each point of the image to the corresponding point in the pre-image, the center of rotation is at the intersection of the perpendicular bisectors of all of those segments. The representation of angles on the coordinate plane is called Standard Position. To rotate around a different reference point, select the Rotate tool. Then Alt‑click (Windows) or Option‑click (Mac OS) where you want the reference point to be in the document window. To rotate around the center point, choose Object > Transform > Rotate, or double-click the Rotate tool.

Comments
  • can you post your layout xml?
  • @PratikPopat added layout xml
  • Then your problem are probably, that your images are not having their center in the middle of the picture self.
  • If i place static image, it shows all at center point. while rotating its not.
  • It shouldn't, but ok. What if you use some scaletype?