Reference version

间隔器

一个用于在元素之间添加灵活间距的 Jetpack Compose Spacer 组件。

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.

关于跨平台用法,请查看通用的 Spacer —— 它会根据平台渲染相应的原生组件。

Expo UI Spacer 与官方 Jetpack Compose Spacer API 一致,用于在布局中的元素之间添加可伸缩或固定大小的间距。

Two boxes pushed to opposite ends of a Row by a Spacer with weight modifier

安装

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.

用法

带 weight 的 Spacer

使用 weight() 修饰符使 spacer 在 RowColumn 中按比例填充可用空间。

SpacerWeightExample.tsx
import { Host, Row, Spacer, Text } from '@expo/ui/jetpack-compose'; import { fillMaxWidth, weight } from '@expo/ui/jetpack-compose/modifiers'; export default function SpacerWeightExample() { return ( <Host matchContents> <Row modifiers={[fillMaxWidth()]}> <Text>左侧</Text> <Spacer modifiers={[weight(1)]} /> <Text>右侧</Text> </Row> </Host> ); }

带固定尺寸的 Spacer

使用 heightwidth 修饰符创建一个具有固定尺寸的 spacer。

SpacerFixedSizeExample.tsx
import { Host, Column, Spacer, Text } from '@expo/ui/jetpack-compose'; import { height } from '@expo/ui/jetpack-compose/modifiers'; export default function SpacerFixedSizeExample() { return ( <Host matchContents> <Column> <Text>上方</Text> <Spacer modifiers={[height(24)]} /> <Text>下方(24dp 间距)</Text> </Column> </Host> ); }

API

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

Component

Spacer

Android

Type: React.Element<SpacerProps>

A spacer component that fills available space. Use with the weight() modifier to create flexible spacing in Row or Column layouts.

Example

<Row> <Text>Left</Text> <Spacer modifiers={[weight(1)]} /> <Text>Right</Text> </Row>

SpacerProps

modifiers

Android
Optional • Type: ExpoModifier[]

Modifiers for the component. Use weight() modifier to make the spacer flexible.