创建有限的可滚动列表
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
滚动列表有助于管理数据集、创建自适应设计,并简化导航。您可以使用有限滚动列表在应用中显示较少数量的项。如需避免较大数据集或长度未知的列表出现性能问题,请参阅使用列表和分页延迟加载数据。
版本兼容性
此实现要求将项目 minSDK 设置为 API 级别 21 或更高级别。
依赖项
创建垂直滚动列表
使用以下代码创建垂直滚动列表:
@Composable
private fun ScrollBoxes() {
Column(
modifier = Modifier
.background(Color.LightGray)
.size(100.dp)
.verticalScroll(rememberScrollState())
) {
repeat(10) {
Text("Item $it", modifier = Modifier.padding(2.dp))
}
}
}
代码要点
结果
图 1. 垂直滚动列表。
包含本指南的集合
本指南属于以下精选快速入门集合,这些集合涵盖了更广泛的 Android 开发目标:
显示列表或网格
借助列表和网格,您的应用可以以视觉上令人愉悦且易于用户使用的形式显示集合。
显示互动组件
了解如何使用可组合函数根据 Material Design 设计系统轻松创建美观的界面组件。
Compose 基础知识(视频合集)
本系列视频介绍了各种 Compose API,可让您快速了解可用 API 以及如何使用它们。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-02-06。
[[["易于理解","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-02-06。"],[],[],null,["# Create a finite scrollable list\n\n\u003cbr /\u003e\n\nScrollable lists can help manage datasets, create responsive designs, and\nfacilitate navigation. You can display smaller sets of items in your app\nby using a finite scrolling list. To avoid performance issues with larger\ndatasets or a list of unknown length, see\n[Lazily load data with lists and Paging](/develop/ui/compose/quick-guides/content/lazily-load-list).\n\nVersion compatibility\n---------------------\n\nThis implementation requires that your project minSDK be set to API level 21 or\nhigher.\n\n### Dependencies\n\n### Kotlin\n\n\u003cbr /\u003e\n\n```kotlin\n implementation(platform(\"androidx.compose:compose-bom:2025.08.00\"))\n \n```\n\n\u003cbr /\u003e\n\n### Groovy\n\n\u003cbr /\u003e\n\n```groovy\n implementation platform('androidx.compose:compose-bom:2025.08.00')\n \n```\n\n\u003cbr /\u003e\n\nCreate a vertical scrolling list\n--------------------------------\n\nUse the following code to create a vertical scrolling list:\n\n\n```kotlin\n@Composable\nprivate fun ScrollBoxes() {\n Column(\n modifier = Modifier\n .background(Color.LightGray)\n .size(100.dp)\n .verticalScroll(rememberScrollState())\n ) {\n repeat(10) {\n Text(\"Item $it\", modifier = Modifier.padding(2.dp))\n }\n }\n}https://github.com/android/snippets/blob/dd30aee903e8c247786c064faab1a9ca8d10b46e/compose/snippets/src/main/java/com/example/compose/snippets/touchinput/gestures/GesturesSnippets.kt#L112-L124\n```\n\n\u003cbr /\u003e\n\n### Key points about the code\n\n- Sets the [`Column`](/reference/kotlin/androidx/compose/foundation/layout/package-summary#Column(androidx.compose.ui.Modifier,androidx.compose.foundation.layout.Arrangement.Vertical,androidx.compose.ui.Alignment.Horizontal,kotlin.Function1)) scrolling behavior with the [`verticalScroll`](/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).verticalScroll(androidx.compose.foundation.ScrollState,kotlin.Boolean,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean)) modifier and the [`rememberScrollState`](/reference/kotlin/androidx/compose/foundation/package-summary#rememberScrollState(kotlin.Int)) function.\n- To create a horizontal scrolling list, create a [`Row`](/reference/kotlin/androidx/compose/foundation/layout/package-summary#Row(androidx.compose.ui.Modifier,androidx.compose.foundation.layout.Arrangement.Horizontal,androidx.compose.ui.Alignment.Vertical,kotlin.Function1)) with a [`horizontalScroll`](/reference/kotlin/androidx/compose/foundation/package-summary#(androidx.compose.ui.Modifier).horizontalScroll(androidx.compose.foundation.ScrollState,kotlin.Boolean,androidx.compose.foundation.gestures.FlingBehavior,kotlin.Boolean)) modifier.\n\nResults\n-------\n\n\u003cbr /\u003e\n\n**Figure 1.** A vertical scrolling list.\n\n\u003cbr /\u003e\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\n### Display interactive components\n\nLearn how composable functions can enable you to easily create beautiful UI components based on the Material Design design system. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/display-interactive-components) \n\n### Compose basics (video collection)\n\nThis series of videos introduces various Compose APIs, quickly showing you what's available and how to use them. \n[Quick guide collection](/develop/ui/compose/quick-guides/collections/compose-basics) \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)"]]