In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
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)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.