Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Android cung cấp ảnh động tải trước sẽ chạy khi bạn thay đổi bố cục. Đặt một thuộc tính trong
để yêu cầu hệ thống Android tạo ảnh động cho những thay đổi về bố cục này, đồng thời thực hiện chế độ mặc định của hệ thống
ảnh động cho bạn.
Dưới đây là ảnh động bố cục mặc định sẽ trông như thế nào khi thêm mục vào danh sách:
Hình 1. Ảnh động bố cục.
Tạo bố cục
Trong tệp XML bố cục của hoạt động, hãy đặt thuộc tính android:animateLayoutChanges
vào true cho bố cục mà bạn muốn bật ảnh động:
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-08-04 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-04 UTC."],[],[],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```"]]