Android rotate animation

21 12 2013

Here is how to make view infinetely rotate around its center:

1. Define animation in xml

Put this file in /res/anim:

<?xml version="1.0" encoding="utf-8"?>
<rotate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="2500"
    android:interpolator="@android:anim/linear_interpolator"
    android:pivotX="50%"
    android:pivotY="50%"
    android:repeatCount="infinite"
    android:repeatMode="restart"
    android:toDegrees="360" >

</rotate>

2. Load animation in java file

I load it in onCreate and keep it as a class field. Thanks to that I can access rotateAnim field to start or stop animation:

Animation rotateAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.rotate);

3. Start / stop animation on view

Here is how to start and stop animation:

view.startAnimation(rotateAnimation);
view.clearAnimation();

Did I help you?
I manage this blog and share my knowledge for free sacrificing my time. If you appreciate it and find this information helpful, please consider making a donation in order to keep this page alive and improve quality

Donate Button with Credit Cards

Thank You!

Advertisements

Actions

Information

One response

10 05 2016
Anonymous

Very good… thanks a lot

Give Your feedback:

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: