Android Programming Realization of RotateAnimation Setting Center Point Rotation Animation Effect
- 2021-08-17 01:10:42
- OfStack
This article describes the example of Android programming to achieve RotateAnimation set center point rotation animation effect. Share it for your reference, as follows:
In xml settings:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="800" // Set animation duration
android:fromDegrees="0.0" // Set the angle at which the animation begins
android:interpolator="@android:anim/linear_interpolator"
android:pivotX="50.0%" // Sets the animation relative to the control's x Position of coordinates
android:pivotY="50.0%" // Sets the animation relative to the control's y Position of coordinates
android:repeatCount="infinite" // Set up a wireless loop
android:toDegrees="360.0" /> // Set the rotation angle at the end of 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);
anim.setFillAfter(true); // Set to keep the last state of animation
anim.setDuration(3000); // Set animation time
anim.setInterpolator(new AccelerateInterpolator()); // Set the inserter
imageview.startAnimation(anim);
}
Android animation Interpolator inserter, relatively simple and commonly used:
(1) LinearInterpolator: The rate of change of animation is linear from beginning to end.
(2) AccelerateInterpolator: From the beginning to the end of animation, the rate of change is an accelerated process.
(3) DecelerateInterpolator: From the beginning to the end of animation, the rate of change is a deceleration process.
(4) CycleInterpolator: From the beginning to the end of animation, the rate of change is a sinusoidal curve that loops a given number of times.
(5) AccelerateDecelerateInterpolator: From the beginning to the end of animation, the rate of change is the process of accelerating first and then decelerating.
More readers interested in Android can check the topics of this site: "Summary of Android Development Animation Skills", "Introduction and Advanced Tutorial of Android Development", "Summary of View Skills in Android View", "Summary of activity Operation Skills in Android Programming", "Summary of Android File Operation Skills", "Summary of Android Resource Operation Skills" and "Summary of Android Control Usage"
I hope this article is helpful to everyone's Android programming.