当我将{alignItems: 'center', justifyContent: 'center'}应用于styleprops 时,出现以下错误,

ScrollView子布局必须通过

然后将同样的样式应用于contentContainerStyle,效果很好.我无法理解stylecontentContainerStyle的基本区别以及何时使用它们.

我假设当调用ScrollView时,调用两个views.style适用于父母ViewcontentContainerStyle适用于子女View.

如果我错了,请纠正我.谢谢

推荐答案

你是对的,这样想,ScrollView是一种特殊的视图,ScrollView有两个部分:

  1. 容器(灰盒),它是外部视图,其高度不能超过windows 高度的100%

  2. 内容(用蓝色标记)是内部,它可以高于窗口高度,它是容器内移动的内容.

enter image description here

ScrollView style定义ScrollView的外部容器,例如它的高度和与同级元素的关系

ScrollView contentContainerStyle定义了它的内部容器,例如项目对齐、填充等

React-native相关问答推荐

@testing-library/react-native -> 渲染 -> TypeError:无法读取未定义的属性(读取存在)

到达安装依赖项时 EAS 构建错误

我们在react钩子中还需要功能性的 setState 方式吗?

如何 break .map 功能

React-Native Android - 找不到 com.android.tools:common

如何在 React Native 中将静态图像拉伸为背景?

如何从 React Native-App 中的 res/drawable-folder 加载图像?

由于端口 8081 sunproxyadmin,无法打包 react native

React-Native: measure测量一个视图

使用 applicationIdSuffix 时 React Native 应用程序不会启动

使用 React Native 打开 iOS iPad 模拟器

Rich ReactNative TextInput

加载远程图像失败后加载本map像

我可以使用 react native 开发 pwa

React Native 不支持在 Windows 上开发?

当前文件夹中的 react-native init

如何在 React Native 中重复图案图像以创建背景?

com.facebook.react.bridge.readablenativemap 不能转换为 java.lang.string

React Context:TypeError:render is not a function

React Native:任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'的执行失败