-
On récupère un ViewPropertyAnimator en appelant
view.animate()
-
On modifie ensuite les propriétés :
-
alpha, rotation, scale, translation, position…
-
-
On peut ensuite préciser un interpolator :
-
permet de rendre le mouvement moins brut
-
-
On instancie le layout contenant notre ViewPager
-
On définit son PagerAdapter qui définit :
-
Le nombre de pages à afficher
-
La méthode getItem qui retourne le fragment correspondant à l’index en paramètre
-
-
Voir dans le projet Coogle AnimationsDemo
-
CardFlip
-
-
Fichiers :
-
src/CardFlipActivity.java
-
animator/card_flip_right_in.xml
-
animator/card_flip_right_out.xml
-
animator/card_flip_left_in.xml
-
animator/card_flip_left_out.xml
-
layout/fragment_card_back.xml
-
layout/fragment_card_front.xml
-
-
On créée une ressource xml :
<animation-list android:id="@+id/selected" android:oneshot="false">
<item android:drawable="@drawable/img1" android:duration="50" />
<item android:drawable="@drawable/img2" android:duration="30" />
<item android:drawable="@drawable/img3" android:duration="50" />
<item android:drawable="@drawable/img4" android:duration="40" />
</animation-list>
-
On la lance :
ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);
img.setBackgroundResource(R.drawable.spin_animation);
// On récupère le fond, qui a été compilé en objet AnimationDrawable
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
// On démarre l'animation (en boucle par défaut)
frameAnimation.start();