Add rotation animations in Android Actionbar

Source: Internet
Author: User

It is often seen that many apps put a refresh button on the Actionbar to refresh the page content.

When this button is clicked, the button rotates continuously, while accessing the network to refresh the content, the animation stops when the refresh is complete.

The main implementation logic is as follows:

Here we use a ImageView set to MenuItem Actionview, so we can use this ImageView to display the rotation animation ImageView Refreshactionview = new ImageView ( this); Refreshactionview.setimageresource (Drawable.ic_action_refresh); Refreshitem.setactionview ( Refreshactionview);         Display Refresh Animation Animation animation = Animationutils.loadanimation (this, Anim.refresh); Animation.setrepeatmode ( Animation.restart); Set the animation from the beginning Animation.setrepeatcount (animation.infinite); refreshactionview.startanimation (Animation);
It turns out that the animation will stop only once, as described above. Later on the internet to look up information,both methods of Setrepeatmode and Setrepeatcount must be written in XML and cannot be set directly by code. as follows:
<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <rotate        android:interpolator= "@android: Anim/linear_interpolator"        android:duration= "2000"        android:fromdegrees= "0"        android:todegrees= "android:pivotx="        50% "        android:pivoty=" 50% "        android:repeatmode= "Restart"        android:repeatcount= "Infinite"        /></set>
according to the above, the animation can be executed in a loop, but there will be a short pause between each animation and the experience is not good. This is a set of Intepolator, this is used to modify the animation effect, define the rate of change in animation, can make the existing animation effect accelerated (acceleration), decelerated (deceleration), repeated (repetition), bounced (bounce) and so on. but I have set up above, why still not work? Originally, this attribute needs to be placed in the set, that is:
<set xmlns:android= "http://schemas.android.com/apk/res/android"    android:interpolator= "@android: anim/ Linear_interpolator ">    <rotate        android:duration=" "        android:fromdegrees=" 0 "        android: Todegrees= "android:pivotx="        50% "        android:pivoty=" 50% "android:repeatmode="        restart "        Android : repeatcount= "Infinite"        /></set>
that's fine.


Add rotation animations in Android Actionbar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.