Reference version

This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

LazyRow

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

Android
Included in Expo Go
Recommended version:
~58.0.1

一种采用延迟加载的水平列表组件,仅渲染可见项目以实现高效滚动。有关更多信息,请参阅 Jetpack Compose 官方文档。

LazyRow 在水平滚动列表中渲染彩色类别卡片LazyRow 在水平滚动列表中渲染彩色类别卡片

安装

Terminal
- npx expo install @expo/ui
- yarn expo install @expo/ui
- pnpm expo install @expo/ui
- bun expo install @expo/ui

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

用法

基本延迟加载行

BasicLazyRow.tsx
import { Host, LazyRow, Text, useMaterialColors, } from '@expo/ui/jetpack-compose'; import { border, padding, } from '@expo/ui/jetpack-compose/modifiers'; const items = Array.from( { length: 100 }, (_, i) => `Item ${i + 1}` ); export default function BasicLazyRow() { const colors = useMaterialColors(); return ( <Host style={{ height: 100 }}> <LazyRow> {items.map(item => ( <Text key={item} style={{ fontSize: 28 }} color={colors.onBackground} modifiers={[ border(1, colors.outline), padding(12, 6, 12, 6), ]}> {item} </Text> ))} </LazyRow> </Host> ); }

使用排列方式

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

LazyRowArrangement.tsx
import { Host, LazyRow, Text, useMaterialColors, } from '@expo/ui/jetpack-compose'; import { border, padding, } from '@expo/ui/jetpack-compose/modifiers'; export default function LazyRowArrangement() { const colors = useMaterialColors(); return ( <Host style={{ height: 100 }}> <LazyRow horizontalArrangement={{ spacedBy: 16 }} verticalAlignment="center"> <Text style={{ fontSize: 28 }} color={colors.onBackground} modifiers={[ border(1, colors.outline), padding(12, 6, 12, 6), ]}> Spaced item 1 </Text> <Text style={{ fontSize: 28 }} color={colors.onBackground} modifiers={[ border(1, colors.outline), padding(12, 6, 12, 6), ]}> Spaced item 2 </Text> <Text style={{ fontSize: 28 }} color={colors.onBackground} modifiers={[ border(1, colors.outline), padding(12, 6, 12, 6), ]}> Spaced item 3 </Text> </LazyRow> </Host> ); }

使用内容内边距

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

LazyRowPadding.tsx
import { Host, LazyRow, Text, useMaterialColors, } from '@expo/ui/jetpack-compose'; import { border, padding, } from '@expo/ui/jetpack-compose/modifiers'; export default function LazyRowPadding() { const colors = useMaterialColors(); return ( <Host style={{ height: 100 }}> <LazyRow contentPadding={{ start: 16, top: 8, end: 16, bottom: 8 }}> <Text style={{ fontSize: 28 }} color={colors.onBackground} modifiers={[ border(1, colors.outline), padding(12, 6, 12, 6), ]}> Padded item 1 </Text> <Text style={{ fontSize: 28 }} color={colors.onBackground} modifiers={[ border(1, colors.outline), padding(12, 6, 12, 6), ]}> Padded item 2 </Text> <Text style={{ fontSize: 28 }} color={colors.onBackground} modifiers={[ border(1, colors.outline), padding(12, 6, 12, 6), ]}> Padded item 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: 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: 'center' | 'start' | 'end' | 'spaceBetween' | 'spaceAround' | 'spaceEvenly' | { spacedBy: number }

modifiers

Android
Optional • Type: ModifierConfig[]

Modifiers for the component.

verticalAlignment

Android
Optional • Literal type: string

The vertical alignment of items.

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