ScrollView 中的 style 与 contentContainerStyle? [英] style Vs contentContainerStyle in ScrollView?

查看:33
本文介绍了ScrollView 中的 style 与 contentContainerStyle?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将 {alignItems: 'center', justifyContent: 'center'} 应用到 style 道具时,出现以下错误,

When I apply {alignItems: 'center', justifyContent: 'center'} to style prop, got following error,

ScrollView 子布局必须通过contentContainerStyle 道具

ScrollView child layout must be applied through the contentContainerStyle prop

然后将相同的样式应用到 contentContainerStyle 并且工作正常.我无法理解 stylecontentContainerStyle 之间的基本区别以及何时使用它们.

then applied same styling to contentContainerStyle and worked fine. I am unable to understand the basic difference between style and contentContainerStyle and when to use them.

我假设在调用 ScrollView 时,会调用两个 views.style 适用于父 ViewcontentContainerStyle 适用于子 View.

I am assuming that when ScrollView is called, two views are called. style applicable to parent View and contentContainerStyle applicable to child View.

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

Please correct me if I am wrong. Thanks.

推荐答案

你说得对,这样想,ScrollView是一种特殊的View,ScrollView有两部分:

You're correct, think of it like this, ScrollView is a special kind of View, ScrollView has two parts:

  1. Container(灰色框),是外部View,高度不能超过窗口高度的100%

  1. Container (the grey box), it's the outside View, its height can't exceed 100% of the window height

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

Content (marked in blue) is the inner part, it can be higher than the window height, it's what's moving inside the container.

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

ScrollView style defines the outer container of the ScrollView, e.g its height and relations to siblings elements

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

ScrollView contentContainerStyle defines the inner container of it, e.g items alignments, padding, etc

这篇关于ScrollView 中的 style 与 contentContainerStyle?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆