Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
323 views
in Technique[技术] by (71.8m points)

React Native flex布局问题

React Native使用flex:1;的时候并不是等分布局,

<View style={{height: 100, flexDirection: 'row'}}>
    <Text style={{backgroundColor: 'red', flex: 1, flexGrow: 1}}>的撒打算</Text>
    <Text style={{backgroundColor: 'green', flex: 1, flexGrow: 1}}>撒打算的撒打算打算的撒打算</Text>
    <Text style={{backgroundColor: 'blue', flex: 1, flexGrow: 1}}>的撒打算</Text>
</View>

如下图所示:

clipboard.png
并没有平分布局,感觉是平分了剩余空间。我使用了react-navigation的TabNavigator路由组件,如果不使用这个组件,显示是正常的,请问这是什么问题?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

在父级的View上,添加width属性,指定父width为当前屏幕的宽度,就可以解决这个弹性布局的问题了,这是因为使用了react-navigation的TabNavigator组件,这个组件的第一个Tab页面存在flex布局的问题。链接描述


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...