Je voudrais ajouter un exemple complet d'animer une icône de progression sur ImageView, il est basé sur la réponse Mark Hetherington.
Donc, mon animation se présente comme suit:
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="-360"
android:duration="100"
android:drawable="@drawable/ic_loop_black_24dp"
/>
icône vient de https://material.io/icons/
alors ma mise en page contient un ImageView comme suit:
<ImageView
android:id="@+id/progress"
android:layout_marginTop="0dp"
android:layout_marginLeft="-3dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:visibility="gone"
android:scaleType="fitCenter"
android:background="@drawable/progress_anim"
android:layout_gravity="center_horizontal|center_vertical"
/>
et enfin dans le code quand je dois montrer l'animation que je fais:
RotateDrawable rotateDrawable = ((RotateDrawable)progressImage.getBackground());
ObjectAnimator anim = ObjectAnimator.ofInt(rotateDrawable, "level", 0, 10000);
anim.setDuration(1000);
anim.setRepeatCount(ValueAnimator.INFINITE);
anim.start();
Je ne comprends pas la question. voulez-vous avoir une animation, ou simplement faire pivoter l'image à l'intérieur? Pour la rotation, consultez ce post: http://stackoverflow.com/a/21376008/878126 –