Android: animated custom views

前端 未结 4 741
一整个雨季
一整个雨季 2021-02-02 12:07

EDIT 2: new official training guide

The Developers site released a training guide for UI related stuff, this is the index:

  • Animations Overview
  • Pro
4条回答
  •  被撕碎了的回忆
    2021-02-02 12:43

    "Filling up a glass of water" animation is direct canditate of implementing via frame animation, i.e. changing pictures one after the other. Here you can see a nice blog post describing how to implement this kind of animation, which basically is the same as "filling up a glass of water" you mentioned:

    The other animation look slightly difficult at first glance.

    But after turning on "Show layout bounds" you can see there is no magic there. Basically this is just a translation animation, which translates a view from one position to another. In case of this animation the difficult part is to implement the algorithm of finding translation coordinates. After that animating is just a couple lines of code via scene transition animation.

    // assuming at this step all the views are at the initial position at x0, y0
    TransitionManager.beginDelayedTransition(rootLayout);
    // here set view coordinates to x1, y1 - the final position
    

    Transitions framework will do the rest for you. It will find the delta and perform animation for you. Here you will find a nice article by Lucas Rocha.

提交回复
热议问题