React Native ScrollView

2025年3月17日 | 阅读 3 分钟

ScrollView 是一个通用的可滚动容器,可以在其中滚动多个子组件和视图。 在 ScrollView 中,我们可以沿垂直水平方向滚动组件。 默认情况下,ScrollView 容器垂直滚动其组件和视图。 要水平滚动其组件,它使用 props horizontal: true(默认值:horizontal: false)。

ScrollView 的 Props

alwaysBounceVerticalonScrollhorizontal
contentContainerStylescrollEnabledbouncesZoomzoomScale
onScrollBeginDragonContentSizeChangemaximumZoomScaleminimumZoomScale
onScrollBeginDragonContentSizeChangemaximumZoomScaleminimumZoomScale
onScrollEndDragcenterContentcontentInsetrefreshControl
pagingEnabledscrollsToTopsnapToAlignmentshowsHorizontalScrollIndicator
snapToStartsnapToEndindicatorStyleshowsHorizontalScrollIndicator

React Native ScrollView 示例

在此示例中,我们使用 Text 和 Button 组件创建一个垂直 ScrollView。

App.js

输出

React Native ScrollView React Native ScrollView

React Native 水平 ScrollView 示例

水平 ScrollView 从左到右滚动组件和视图。 它将通过将 props horizontal 设置为 true (horizontal={true}) 来实现。

App.js

输出

React Native ScrollView React Native ScrollView
下一个主题React Native ListView