Animating Layout Changes

All you need to do is set an attribute in the layout to tell the Android system to animate these layout changes, and system-default animations are carried out for you.

<LinearLayout android:id="@+id/container"
    android:animateLayoutChanges="true"
    ...
/>

Now, all you need to do is add, remove, or update items in the layout and the items are animated automatically:

private ViewGroup mContainerView;
...
private void addItem() {
    View newView;
    ...
    mContainerView.addView(newView, 0);
}

Tip: If you want to supply custom layout animations, create a LayoutTransition object and supply it to the layout with the setLayoutTransition() method.

References
https://developer.android.com/training/animation/layout.html
https://stackoverflow.com/questions/41464629/expand-collapse-animation-in-cardview
https://github.com/mhdr/AndroidSamples/tree/master/104