Auto animate layout updates

Stay organized with collections Save and categorize content based on your preferences.

Android offers pre-loaded animation that the system runs each time you make a change to the layout. All you need to do is set an attribute in the layout to tell the Android system to animate layout changes, and system-default animations are carried out for you.

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

Here's what a default layout animation looks like when adding items to a list:

Create the layout

In your activity's layout XML file, set the android:animateLayoutChanges attribute to true for the layout in which you want to enable animations:

<LinearLayout android:id="@+id/container"

Add, update, or remove items from the layout

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


lateinit var containerView: ViewGroup
private fun addItem() {
    val newView: View = ...

    containerView.addView(newView, 0)


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