Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the method of drawing rotation animation with Android

Shulou Source: shulou.com Published: 2022-06-02 04:09:50 10月03日 Update

In this issue, the editor will bring you about the method of drawing rotation animation in Android. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

1. Preparatory work

First, you need to have a picture to rotate.

You need to think about how to start, end, accelerate, and slow down.

2. Principle of acceleration and deceleration

This animation uses RotateAnimation, and the parameters required for initialization are as follows

Public RotateAnimation (float fromDegrees,float toDegrees,int pivotXType,float pivotXValue,int pivotYType, float pivotYValue) {mFromDegrees = fromDegrees;// start angle mToDegrees = toDegrees;// end angle mPivotXValue = pivotXValue;// determine the type of x-axis coordinates mPivotXType = pivotXType;//x axis value, 0.5f indicates that the type of y-axis coordinates is determined by half the length of the control itself as x-axis mPivotYValue = pivotYValue;// mPivotYType = pivotYType / / the value of the y-axis, 0.5f indicates that half the length of the control itself is the y-axis initializePivotPoint ();}

The so-called rotation animation, in essence, is to specify rotation within a certain period after the above object is initialized.

The so-called acceleration essentially means changing the rotation angle within a set period.

Or modify the period to rotate a certain angle within the preset period.

In short, the angle and cycle must change, which can determine the speed of the animation.

For example, from 360 degrees in 2 seconds to 360 degrees in 1 second is a kind of acceleration

Rotation from 360 degrees in 2 seconds to 720 degrees in 2 seconds is also an acceleration.

On the contrary, it is to slow down.

3. Initialize RotateAnimation rotate = new RotateAnimation (0f, 360 f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setInterpolator (new LinearInterpolator ()); rotate.setDuration (2000); / / set the animation duration period rotate.setRepeatCount (- 1); / / set the number of repeats / / rotate.setFillAfter (true) / / whether the animation remains in the finished state after execution rotate.setStartOffset (10); / / waiting time before execution 4, start start.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {fan.startAnimation (rotate);}}); 5. Acceleration

First, you need to create a global variable

Private int duration=2000

Accelerated exampl

Accelerate.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {if (duration > 10) {duration/=2; / / period divided by 2 angles invariant acceleration (need to consider extremes, so add a judgment)} rotate.setDuration (duration) / / set cycle fan.startAnimation (rotate); / / start rotation}}); 6. Decelerate decelerate.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {if (duration10) {duration/=2;} rotate.setDuration (duration)) Fan.startAnimation (rotate);}}); decelerate.setOnClickListener (new View.OnClickListener () {@ Override public void onClick (View v) {if (duration)

Tags: Period animation angle that is method content coordinates controls time essence extreme times state type part length analysis general professional medium and small Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Huawei Shulou Tech Info Redmi Microsoft