Danh sách lazy trong Compose
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.
Compose cung cấp cho bạn một cách đơn giản và hiệu quả hơn để tạo danh sách cuộn, sử dụng ít dòng mã hơn so với RecyclerView
. Tìm hiểu cách sử dụng bố cục tải lười để tạo danh sách cho phép bạn thêm nội dung vào danh sách theo yêu cầu.
Điểm chính
- Sử dụng bố cục tải lười để thêm nội dung theo yêu cầu cho một số lượng lớn mục hoặc tập dữ liệu lớn, giúp tăng hiệu suất và khả năng phản hồi của ứng dụng.
- Phương pháp này cho phép bạn tập trung vào việc mô tả nội dung của mục trong khi danh sách tải lười xử lý mọi thứ khác.
- Bạn có thể mô tả một mục bằng cách sử dụng khối
item()
hoặc nhiều mục bằng khối items()
.
LazyListState
là một đối tượng trạng thái quan trọng lưu trữ vị trí cuộn và chứa thông tin hữu ích trên danh sách.
Tài nguyên
Các bộ sưu tập chứa hướng dẫn này
Hướng dẫn này là một phần của các bộ sưu tập Hướng dẫn nhanh được tuyển chọn này, bao gồm các mục tiêu phát triển Android rộng hơn:
Hiển thị danh sách hoặc lưới
Danh sách và lưới cho phép ứng dụng của bạn hiển thị các bộ sưu tập ở dạng hình ảnh dễ nhìn và dễ sử dụng cho người dù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-07-27 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-07-27 UTC."],[],[],null,["# Lazy lists in Compose\n\n\u003cbr /\u003e\n\nCompose gives you a simpler and more performant way to create scrolling lists,\nusing fewer lines of code than [`RecyclerView`](/reference/androidx/recyclerview/widget/RecyclerView). Learn how to use lazy\nlayouts to create lists that let you add content to lists, on demand. \n\nKey points\n----------\n\n- Use lazy layouts to add content on demand for a significant number of items or large datasets, increasing your app's performance and responsiveness.\n- This approach lets you focus on describing your item content while lazy lists handle everything else.\n- You can describe one item using the [`item()`](/reference/kotlin/androidx/compose/foundation/lazy/LazyListScope#item(kotlin.Any,kotlin.Any,kotlin.Function1)) block or multiple items with the [`items()`](/reference/kotlin/androidx/compose/foundation/lazy/LazyListScope#items(kotlin.Int,kotlin.Function1,kotlin.Function1,kotlin.Function2)) block.\n- [`LazyListState`](/reference/kotlin/androidx/compose/foundation/lazy/LazyListState) is an important state object that stores the scroll position and contains useful information on your list.\n\nResources\n---------\n\n- [Codelab: Basic layouts in Compose](/codelabs/jetpack-compose-layouts#0)\n\nCollections that contain this guide\n-----------------------------------\n\nThis guide is part of these curated Quick Guide collections that cover\nbroader Android development goals: \n\n### Display a list or grid\n\nLists and grids allow your app to display collections in a visually pleasing form that's easy for users to consume. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/display-a-list-or-grid) \n\nHave questions or feedback\n--------------------------\n\nGo to our frequently asked questions page and learn about quick guides or reach out and let us know your thoughts. \n[Go to FAQ](/quick-guides/faq) [Leave feedback](https://issuetracker.google.com/issues/new?component=1573691&template=1993320)"]]