Анимация ImageButton в Android? - PullRequest
       31

Анимация ImageButton в Android?

6 голосов
/ 27 сентября 2011

Я действительно новичок в анимации на Android (и почти все остальное).Есть ли способ оживить ImageButton?Я просто хочу повернуть кнопку иногда.Это все.Любая помощь?

Спасибо.

Ответы [ 2 ]

10 голосов
/ 27 сентября 2011

Попробуйте этот фрагмент кода.

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>

в java-файле

ImageButton imgbt = (ImageButton)findViewById(R.id.your_id);
Animation ranim = (Animation)AnimationUtils.loadAnimation(context, R.anim.rotate);
imgbt.setAnimation(ranim);
7 голосов
/ 24 января 2014

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-код:

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