Skip to content

Latest commit

 

History

History
90 lines (69 loc) · 2.24 KB

11-animations.asc

File metadata and controls

90 lines (69 loc) · 2.24 KB

Android

Quel type d’animations

  • Des animations de propriétés des vues

  • Comme toujours :

    • En Java

    • En XML

ViewPropertyAnimator

  • 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

Démo CrossFade

  • Voir dans le projet Google AnimationsDemo

    • CrossFadeActivity

ViewPager

  • Transitions entre pages

  • Dans la support library

  • Utilise des fragments

  • Swipes par défaut

Utilisation

  • 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

Démo ViewPager

  • Voir dans le projet Google AnimationsDemo

    • ScreenSlideActivity

CardFlipActivity

  • 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

ZoomView

  • Voir dans le projet Coogle AnimationsDemo

    • ZoomActivity

Animation d’images

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