Compose 中的延迟列表
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
与 RecyclerView
相比,Compose 提供了一种更简单、更高效的方式来创建滚动列表,所需的代码行数更少。了解如何使用延迟布局创建列表,以便您按需向列表中添加内容。
要点
- 使用延迟布局可按需为大量项或大型数据集添加内容,从而提升应用的性能和响应能力。
- 通过这种方法,您可以专注于描述项内容,而延迟列表会处理所有其他事项。
- 您可以使用
item()
代码块描述一件商品,也可以使用 items()
代码块描述多件商品。
LazyListState
是一个重要的状态对象,用于存储滚动位置,并包含列表中实用的信息。
资源
包含本指南的集合
本指南属于以下精选快速入门集合,这些集合涵盖了更广泛的 Android 开发目标:
显示列表或网格
借助列表和网格,您的应用可以以视觉上令人愉悦且易于用户使用的形式显示集合。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-27。"],[],[],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)"]]