「React Native笔记」 踩坑contentContainerStyle属性

「React Native笔记」 踩坑contentContainerStyle属性

  • 资源类别: JavaScript
  • 如遇问题:请底部留言反馈或联系客服
用React Native里的ScrollView组件,给ScrollView直接加了justifyContent或alignitems属性后会报错。问题原因是scrollView和flatlist之类的组件不支持直接添加这两个属性,解决方法是给组件添加contentContainerStyle属性

contentContainerStyle0

React Native里的ScrollView组件,给ScrollView直接加了justifyContentalignitems属性后会报错。

contentContainerStyle1

报错信息:

ScrollView child layout ([“alignitems”, “justifyContent”]) must be applied through the contentContainerStyle prop

问题原因是scrollView和flatlist之类的组件不支持直接添加这两个属性,解决方法是给组件添加contentContainerStyle属性,这些样式会应用到一个内层的内容容器上,所有的子视图都会包裹在内容容器内,在这个属性后面指定对应的样式即可:

contentContainerStyle2

contentContainerStyle3

0 条回复A文章作者M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索