Compose 中的 Lazy 清單
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Compose 提供更簡單且效能更高的捲動清單建立方式,所需的程式碼行數比 RecyclerView
少。瞭解如何使用延遲版面配置建立清單,讓您可視需要在清單中加入內容。
重點
- 使用延遲版面配置,可針對大量項目或大型資料集,按需新增內容,進而提升應用程式的效能和回應速度。
- 您可以透過這種做法專注於描述項目內容,而延遲清單會處理其他所有事物。
- 您可以使用
item()
區塊說明一個項目,也可以使用 items()
區塊說明多個項目。
LazyListState
是重要的狀態物件,用於儲存捲動位置,並包含清單中的實用資訊。
資源
包含此指南的集合
本指南是精選的快速指南系列之一,涵蓋更廣泛的 Android 開發目標:
顯示清單或格狀
清單和格線可讓應用程式以視覺上賞心悅目且使用者易於取用的形式顯示集合。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間: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"]],["上次更新時間: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)"]]