1

I have a RecyclerView with CardView as item in it. CardView has the Arrow icon to show details in the same CardView, but I don't want to set is GONE or VISIBLE because this action has no good looking animation. I tried to set android:animateLayoutChanges="true" on my CardView and I got this: (this is not my screen but it contains the same problem)

enter image description here

But once I click on the arrow again to collapse the supporting text, the card below overlaps the card I've clicked during the animation. How can I avoid this overlapping? I tried to call TransitionManager.beginDelayedTransition(CardView); but looks like it doesn't help me..

Den
  • 1,284
  • 2
  • 14
  • 33

1 Answers1

6

You can try removing android:animateLayoutChanges="true" and calling TransitionManager.beginDelayedTransition(MainRootView); (note that call parameter is RootView and not CardView).

If it wouldn't do you should do collapsing-expanging by your own. Here is a good example of view height animating.

Ekalips
  • 1,473
  • 11
  • 20
  • What does `beginDelayedTransition` do? – Ajil O. Jul 27 '17 at 07:55
  • What is RootView is this case? RecyclerView? – Den Jul 27 '17 at 07:56
  • @AjilO. `beginDelayedTransition` tells system that something will be changed in layout and it should be animated. For example: you change alpha of view (with `view.setAlpha()`) and system will animate your alpha from previous value to new one. You should google this for better explanations. –  Ekalips Jul 27 '17 at 08:01
  • @Den I suggest starting from really root view (like root view of activity) and then go down to hierarchy –  Ekalips Jul 27 '17 at 08:02
  • @Den, yes, it is the `RecyclerView`. – azizbekian Jul 27 '17 at 08:04
  • 1
    Amazing - with this its super easy to have a horizontal recyclerview that auto resizes its height with a smooth animation ! – slott Aug 25 '17 at 19:04
  • Perfect solution. Working like a charm. Thanks – Francis Dec 18 '18 at 14:10
  • This works great as a way to animate! But you need to call this right before any change you want animated. No need to mess around with viewGroup.setLayoutTransition, which seems to not work well when coordinating with multiple items and definitely doesn't work right in a RecyclerView. – Flyview Feb 02 '19 at 21:42