SoFunction
Updated on 2025-04-09

Android programming to implement RotateAnimation setting center point rotation animation effect

This article describes the Android programming implementation of RotateAnimation to set the center point rotation animation effect. Share it for your reference, as follows:

Settings in xml:

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:andro
  android:duration="800" // Set the animation duration  android:fromDegrees="0.0" // Set the angle at the beginning of the animation  android:interpolator="@android:anim/linear_interpolator"
  android:pivotX="50.0%" // Set the position of the animation relative to the x coordinate of the control  android:pivotY="50.0%" // Set the position of the animation relative to the y coordinate of the control  android:repeatCount="infinite" // Set wireless loop  android:toDegrees="360.0" /> // Set the rotation angle at the end of the animation

Set in the code, mainly the coordinates of x and y are the center points:

public void rotateAnim() {
    Animation anim =new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    (true); // Set to keep the animation last state    (3000); // Set animation time    (new AccelerateInterpolator()); // Set the inserter    (anim);
}

Android animation Interpolator inserter, relatively simple and commonly used:

(1)LinearInterpolator: The change rate of animation changes linearly from the beginning to the end.
(2)AccelerateInterpolator: The change rate is an accelerated process from the beginning to the end of the animation.
(3)DecelerateInterpolator: From the beginning to the end of the animation, the change rate is a process of slowing down.
(4)CycleInterpolator: The animation starts to end, the rate of change is the sinusoidal curve of a given number of times looping.
(5)AccelerateDecelerateInterpolator: From the beginning to the end of the animation, the change rate is the process of acceleration first and then deceleration.

For more information about Android related content, please check out the topic of this site:Android development animation skills summary》、《Android development introduction and advanced tutorial》、《Android View View Tips Summary》、《Android programming activity operation skills summary》、《Android file operation skills summary》、《Android resource operation skills summary"and"Android control usage summary

I hope this article will be helpful to everyone's Android programming design.