ImageButton animation in android?

I'm really new to android animation (and pretty much everything else). Is there a way to animate ImageButton? I just want to turn the button sometimes. It's all. Any help?

Thanks.

+6
source share
2 answers

Try this piece of code.

rotate.xml

<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <rotate android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:repeatCount="0" android:duration="1000" /> </set> 

in java file

 ImageButton imgbt = (ImageButton)findViewById(R.id.your_id); Animation ranim = (Animation)AnimationUtils.loadAnimation(context, R.anim.rotate); imgbt.setAnimation(ranim); 
+10
source

rotate.xml

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

Java Code:

 RotateAnimation rotateAnimation = (RotateAnimation) AnimationUtils.loadAnimation(context,R.anim.rotate); view.startAnimation(rotateAnimation); 
+7
source

All Articles