[null,null,["最后更新时间 (UTC):2025-08-04。"],[],[],null,["# Auto-animate layout updates\n\nAndroid offers preloaded animation that runs when you change the layout. Set an attribute in the\nlayout to tell the Android system to animate these layout changes, and it carries out system-default\nanimations for you.\n| **Tip** : If you want to supply custom layout animations, create a [LayoutTransition](/reference/android/animation/LayoutTransition) object and supply it to the layout with the [setLayoutTransition()](/reference/android/view/ViewGroup#setLayoutTransition(android.animation.LayoutTransition)) method.\n\nHere's what a default layout animation looks like when adding items to a list: \n**Figure 1.** Layout animation. \n\nCreate the layout\n-----------------\n\nIn your activity's layout XML file, set the `android:animateLayoutChanges` attribute\nto `true` for the layout that you want to enable animations for: \n\n```xml\n\u003cLinearLayout android:id=\"@+id/container\"\n android:animateLayoutChanges=\"true\"\n ...\n/\u003e\n```\n\nAdd, update, or remove items from the layout\n--------------------------------------------\n\nAdd, remove, or update items in the layout, and the items are animated automatically: \n\n### Kotlin\n\n```kotlin\nlateinit var containerView: ViewGroup\n...\nprivate fun addItem() {\n val newView: View = ...\n\n containerView.addView(newView, 0)\n}\n```\n\n### Java\n\n```java\nprivate ViewGroup containerView;\n...\nprivate void addItem() {\n View newView;\n ...\n containerView.addView(newView, 0);\n}\n```"]]