欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

ScrollView child layout ([alignItems]) 错误

发布时间:2025/4/5 编程问答 42 豆豆
生活随笔 收集整理的这篇文章主要介绍了 ScrollView child layout ([alignItems]) 错误 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

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

<ScrollView style={{alignItems:'center'}}>
<FlatList
data={this.state.sellData}
renderItem={({item})=><SellItem ordernum={item.orderNumber} time={item.time} memberid={item.memberId}
number={item.number} price={item.price} total_amount={item.total_amount}
sellCallBack={
()=>{
this.sellDba(item.orderId)
}
}
/>}
/>
</ScrollView>

报错(ScrollView child layout ([“alignitems”, “justifyContent”]) must be applied through the contentContainerStyle prop)如下:

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

<ScrollView contentContainerStyle={{alignItems:'center'}}>
<FlatList
data={this.state.sellData}
renderItem={({item})=><SellItem ordernum={item.orderNumber} time={item.time} memberid={item.memberId}
number={item.number} price={item.price} total_amount={item.total_amount}
sellCallBack={
()=>{
this.sellDba(item.orderId)
}
}
/>}
/>
</ScrollView>

转载于:https://blog.51cto.com/13238147/2371910

总结

以上是生活随笔为你收集整理的ScrollView child layout ([alignItems]) 错误的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。