Skip to main content

Notes - Get Animated (Android Dev Summit '18)

note

This article has been translated by Gemini.

In this Notes article, I roughly jotted down notes in English from the content of the English session video/podcast. This article is intended to be read as a reference while watching the video. I hope this article helps you even a little when you watch the actual video. (Please feel free to contact me if there are any errors or typos! m(__)m)

This article is based on Get Animated (Android Dev Summit ‘18).

f🆔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, 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 is currently necessary for window animations, but it seems better to use other APIs for other animations.
  • MotionLayout will allow for amazing animations, but it should be used in the right place alongside existing APIs.
  • I was very surprised to see Sumitomo-san’s Twitter account featured in the MotionLayout explanation.