Animate change of view background color on Android

前端 未结 16 1060
孤街浪徒
孤街浪徒 2020-11-22 13:23

How do you animate the change of background color of a view on Android?

For example:

I have a view with a red background color. The background color of the

16条回答
  •  鱼传尺愫
    2020-11-22 14:16

    Another easy way to achieve this is to perform a fade using AlphaAnimation.

    1. Make your view a ViewGroup
    2. Add a child view to it at index 0, with match_parent layout dimensions
    3. Give your child the same background as the container
    4. Change to background of the container to the target color
    5. Fade out the child using AlphaAnimation.
    6. Remove the child when the animation is complete (using an AnimationListener)

提交回复
热议问题