heihei blog

Blog icon by Unsplash https://unsplash.com/@virussinside

Notes - Get Animated (Android Dev Summit '18)

※Notes記事では、英語のセッション動画やポッドキャストの内容を(雑に)英語でメモに書き残すことを行っています。本記事は、あくまで動画を見ながら、参考程度に読んでいただくことを想定しています。Notes記事には雑メモ程度のものだったり、書き起こしのようなものもあります。これから実際の動画を見る際には、本記事の内容が少しでもお役に立てば幸いです。(内容において不備、誤字脱字等ありましたら気軽にご連絡いただけると嬉しいです!m(__)m)

本記事は、Get Animated (Android Dev Summit '18)に関する記事です。

f:id:shaunkawano:20181216212636p:plain

Android Animation APIs

  • View Animations
  • Value Animator
  • Object Animator
  • View Property Animator
  • Transitions
  • Animated Vector Drawable
  • Physics
  • MotionLayout

android.view.animation

is now consider deprecated

  • Measure => Layout => Draw
    • android.view.animation is only applied in Draw process
  • WindowAnimation only accepts android.view.animation so it should be used only here, but otherwise consider it as deprecated
  • You may use it in FragmentTransaction
    • API also accepts Android animator so prefer animator

When to use which Animator

  • ObjectAnimator - general purpose, property animator
  • ValueAnimator - custom animation
  • ViewPropertyAnimator
    • Multiple properties on the same View
    • Fire and forget
  • PropertyValuesHolder - multiple properties on the same object
  • AnimatorSet - choreograph a set of animations

AnimatedVectorDrawable

When to use

  • Icon animation
  • Fire & forget animations
  • Performance critical

Physics

Physics-based Animation

  • Interruptible
  • Continuity
  • Realistic Look

Transitions

  • Shared element activity transitions
  • Window content enter/exit
  • Modularize animations
  • Simple changes

Motion / Animation

Helper

In ConstraintLayout 2.0, all the helpers are exposed for achieving encapsulated behaviors

  • ConstraintLayout utility
  • Apply it to a set of widgets
  • Supported in Android Studio
  • Use Animation APIs in helpers to promote reuse

E.g. Circular Reveal:

@Override
public void updatePostLayout(ConstraintLayout container) {
  super.updatePostLayout(container);
  if (mContainer != container) {
    int rad = (int) Math.hypot(mComputedMaxY - mComputedMinY, mComputedMaxX - mComputedMinX);
    Animator anim = ViewAnimationUtils.createCircularReveal(this, (int) mComputedCenterX - getLeft(), (int) mComputedCenterY - getTop(0, 0, rad);
    anim.setDuration(2000);
    anim.start();
  }
  mContainer = container;
}
<com.example.CircularRevealHelper
    android:id="@+id/helper"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/lake"
    app:constraint_referenced_ids="imageView" />

MotionLayout

  • Only two states: Start to End
  • Where it shines
    • Declarative motion
    • Bespoke motion
    • Touch-driven motion

MotionLayout: Library

  • Part of ConstraintLayout 2.0
  • Released at Google IO'18
  • Built upon ConstraintLayout 1.1
  • Alpha 2

📝

  • android.view.animationはwindow animationには現状必要だが、それ以外のアニメーションには別のAPIを利用するほうが良さそう
  • 今後MotionLayoutが出てきてものすごいアニメーションを表現できるようになると思うが、既存APIとは適材適所で使い分けする必要がありそう
  • MotionLayoutの説明の部分で住友さんのツイッターアカウントが取り上げられていてめちゃ驚いた