LazyColumn
一个用于显示可滚动列表的 Jetpack Compose LazyColumn 组件。
Android
For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.
一个惰性加载的垂直列表组件,只渲染可见项目以实现高效滚动。更多信息请参阅 官方 Jetpack Compose 文档。
安装
Terminal
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基础懒加载列
BasicLazyColumn.tsx
import { Host, LazyColumn, ListItem } from '@expo/ui/jetpack-compose'; const items = Array.from({ length: 100 }, (_, i) => `项目 ${i + 1}`); export default function BasicLazyColumn() { return ( <Host style={{ height: 400 }}> <LazyColumn> {items.map(item => ( <ListItem key={item} headline={item} /> ))} </LazyColumn> </Host> ); }
带排列方式
使用 verticalArrangement 属性来控制项目在列表中的间距。传入类似 'spaceBetween' 的字符串值,或者传入类似 { spacedBy: 8 } 的对象,以便按 dp 设置固定间距。
LazyColumnArrangement.tsx
import { Host, LazyColumn, ListItem } from '@expo/ui/jetpack-compose'; export default function LazyColumnArrangement() { return ( <Host style={{ height: 400 }}> <LazyColumn verticalArrangement={{ spacedBy: 8 }} horizontalAlignment="center"> <ListItem> <ListItem.HeadlineContent>带间距的项目 1</ListItem.HeadlineContent> </ListItem> <ListItem> <ListItem.HeadlineContent>带间距的项目 2</ListItem.HeadlineContent> </ListItem> <ListItem> <ListItem.HeadlineContent>带间距的项目 3</ListItem.HeadlineContent> </ListItem> </LazyColumn> </Host> ); }
带内容内边距
使用 contentPadding 属性为列表内容四周添加以 dp 为单位的内边距。
LazyColumnPadding.tsx
import { Host, LazyColumn, ListItem } from '@expo/ui/jetpack-compose'; export default function LazyColumnPadding() { return ( <Host style={{ height: 400 }}> <LazyColumn contentPadding={{ start: 16, top: 8, end: 16, bottom: 8 }}> <ListItem> <ListItem.HeadlineContent>带内边距的项目 1</ListItem.HeadlineContent> </ListItem> <ListItem> <ListItem.HeadlineContent>带内边距的项目 2</ListItem.HeadlineContent> </ListItem> <ListItem> <ListItem.HeadlineContent>带内边距的项目 3</ListItem.HeadlineContent> </ListItem> </LazyColumn> </Host> ); }
API
import { LazyColumn } from '@expo/ui/jetpack-compose';
Component
Type: React.Element<LazyColumnProps>
A lazy column component that efficiently displays a vertically scrolling list.
Optional • Literal type:
stringThe horizontal alignment of items.
Acceptable values are: 'start' | 'end' | 'center'