Reference version

LazyRow

一个用于显示水平滚动列表的 Jetpack Compose LazyRow 组件。

Android
Included in Expo Go
Bundled version:
~56.0.6

For the complete documentation index, see llms.txt. Use this file to discover all available pages.

一种懒加载的横向列表组件,只渲染可见项以实现高效滚动。有关更多信息,请参阅 官方 Jetpack Compose 文档

LazyRow 在横向滚动列表中渲染彩色分类卡片

安装

Terminal
npx expo install @expo/ui

If you are installing this in an existing React Native app, make sure to install expo in your project.

用法

基础 lazy row

BasicLazyRow.tsx
import { Host, LazyRow, Text } from '@expo/ui/jetpack-compose'; const items = Array.from({ length: 100 }, (_, i) => `Item ${i + 1}`); export default function BasicLazyRow() { return ( <Host style={{ height: 100 }}> <LazyRow> {items.map(item => ( <Text key={item}>{item}</Text> ))} </LazyRow> </Host> ); }

使用排列方式

使用 horizontalArrangement 属性来控制列表中各项的间距。传入类似 'spaceBetween' 的字符串值,或传入类似 { spacedBy: 8 } 的对象,以设置固定的 dp 间距。

LazyRowArrangement.tsx
import { Host, LazyRow, Text } from '@expo/ui/jetpack-compose'; export default function LazyRowArrangement() { return ( <Host style={{ height: 100 }}> <LazyRow horizontalArrangement={{ spacedBy: 16 }} verticalAlignment="center"> <Text>间隔项 1</Text> <Text>间隔项 2</Text> <Text>间隔项 3</Text> </LazyRow> </Host> ); }

使用内容内边距

使用 contentPadding 属性为列表内容周围添加 dp 内边距。

LazyRowPadding.tsx
import { Host, LazyRow, Text } from '@expo/ui/jetpack-compose'; export default function LazyRowPadding() { return ( <Host style={{ height: 100 }}> <LazyRow contentPadding={{ start: 16, top: 8, end: 16, bottom: 8 }}> <Text>带内边距的项 1</Text> <Text>带内边距的项 2</Text> <Text>带内边距的项 3</Text> </LazyRow> </Host> ); }

API

import { LazyRow } from '@expo/ui/jetpack-compose';

Component

LazyRow

Android

Type: React.Element<LazyRowProps>

A lazy row component that efficiently displays a horizontally scrolling list.

LazyRowProps

children

Android
Optional • Type: React.ReactNode

The content to display inside the lazy row.

contentPadding

Android
Optional • Type: ContentPadding

Content padding in dp.

horizontalArrangement

Android
Optional • Literal type: union

The horizontal arrangement of items. Can be a preset string or an object with spacedBy to specify spacing in dp.

Acceptable values are: 'start' | 'end' | 'center' | 'spaceBetween' | 'spaceAround' | 'spaceEvenly' | { spacedBy: number }

modifiers

Android
Optional • Type: ExpoModifier[]

Modifiers for the component.

verticalAlignment

Android
Optional • Literal type: string

The vertical alignment of items.

Acceptable values are: 'top' | 'bottom' | 'center'