Rotate animation android

I’m trying to do a rotating image animation.
I need to rotate an icon around itself just like they do in a progressbar, but what I’m getting is an image rotating around a circle.
Here is my animation code

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

Where am I going wrong in here?
Thanks

  • The efficiency about android canvas drawing
  • WebView shouldOverrideUrlLoading() not called for invalid links
  • ADB throws SecurityException while starting service after system update to Nexus 7: “Caller uid=2000 is not privileged to communicate with user=-2”
  • Google maps v2 not displayed
  • Android Studio: App icon doesn't appear in the home screen or app list
  • Android version check
  • Related posts:

    Fused location provider doesn&#039;t seem to use GPS receiver
    Android Material Design profile page
    ListView with customized Row Layout - Android
    Application won&#039;t start when using `com.android.future.usb.accessory` library
    android.content.res.Resources$NotFoundException for ic_sync_black_24dp.xml
    TextView onClick not responding to single tap
  • Android OpenCV Find Largest Square or Rectangle
  • Prevent Android Studio/Intellij Idea from building project on startup
  • Android: How can i print a variable on eclipse console
  • Rxjava Android how to use the Zip operator
  • Which audio format can be recorded and played back by iPhone and Android?
  • Clarify the Firebase connections
  • 4 Solutions collect form web for “Rotate animation android”

    This is the source code for the layout main.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    
        <Button
            android:id="@+id/testButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="animationText" 
            android:onClick="AnimClick"/>
    
        <ImageView
            android:id="@+id/testImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:contentDescription="image_desc"
            android:scaleType="fitCenter"
            android:src="@drawable/cat2" />
    
    </RelativeLayout>
    

    To implement the rotation animation, we can define the animation by XML or Java code. If we want to write the animation in the xml, we need to create an animation xml file under /res/anim folder. Here, we create a xml file named rotate_around_center_point.xml

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

    and this is my Activity:

    public class MainActivity extends Activity implements OnClickListener {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            Button btn = (Button) findViewById(R.id.testButton);
            btn.setOnClickListener(this);
    
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }
    
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            ImageView animationTarget = (ImageView) this.findViewById(R.id.testImage);
    
            Animation animation = AnimationUtils.loadAnimation(this, R.anim.rotate_around_center_point);
            animationTarget.startAnimation(animation);
    
        }
    
    
    }
    

    You could try with the following code, rather than doing it in XML:

    RotateAnimation rotate = new RotateAnimation(0, 360,
            Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
            0.5f);
    
    rotate.setDuration(4000);
    rotate.setRepeatCount(Animation.INFINITE);
    yourView.setAnimation(rotate);
    

    Well I got where I was wrong. I gave padding to my image which caused it to move aside a little every time it rotated.
    Anyhow I removed the padding and now it’s working just fine.

    Add the following xml in the animation folder

    <?xml version="1.0" encoding="utf-8"?>
    <set xmlns:android="http://schemas.android.com/apk/res/android"
        android:shareInterpolator="false" 
        android:duration="4000" 
        android:fromdegrees="0" 
        android:pivotx="50%" 
        android:pivoty="50%"
        android:todegrees="360" 
        android:toyscale="0.0">
     </set>
    

    Hope this will help you..

    for more information http://www.blazin.in/2013/09/simple-rotate-animation-in-android.html

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.