Collapsing CardView inside RecyclerView when animating

前端 未结 1 1293
情歌与酒
情歌与酒 2020-12-28 17:00

What I\'m trying to do

I have a CardView with a supporting text on the bottom that is GONE by default. I want to make this section of the

1条回答
  •  时光说笑
    2020-12-28 17:41

    Right before you change the visibility, add this line of code:

    TransitionManager.beginDelayedTransition(the rootView containing the cardView, new AutoTransition()); 
    

    You should get a smooth animation. Also remove "animateLayoutChanges=true" from your xml before this.

    As for why this works, calling TransitionManager.beginDelayedTransition() makes the TransitionManger capture current values in the parent ViewGroup and render the animations in the next animation frame. The Transition passed in this case is an AutoTransition, which takes care of all the fading, moving, and resizing in the parent ViewGroup.

    See Transitions and TransitionManager

    Also take care to use Transitions from the support library where appropriate, or perform the neccessary API level checks.

    0 讨论(0)
提交回复
热议问题