开发者

animating ImageButton in android?

开发者 https://www.devze.com 2023-04-07 15:06 出处:网络
I am really new to animations in android (and pretty much anything else). Is there a way to animate an ImageButton? I just want to rotate the button for sometimes. T开发者_运维百科hats all. Any help ?

I am really new to animations in android (and pretty much anything else). Is there a way to animate an ImageButton? I just want to rotate the button for sometimes. T开发者_运维百科hats all. Any help ?

Thanks.


Try this code snippet.

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);


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号