React Native:身高vs屈曲 [英] React Native: Height vs flex
问题描述
在视图中设置多个组件的高度时,在设置高度时是否在柔韧性或高度上有什么区别?
While setting height of multiple components in a view, is there any difference between setting the height in terms of flex or height?
例如,
1) <View>
<View style={{flex:1}}>
</View>
<View style={{flex:3}}>
</View>
</View
2) var windowSize = Dimensions.get('window');
<View>
<View style={{height:windowSize.height/4}}>
</View>
<View style={{height:windowSize.height*3/4}}>
</View>
</View>
推荐答案
是的,当您旋转设备时,flex会在没有窗口的情况下做出响应.
Yes, when you rotate a device flex is responsive where as window isn't.
例如,如果设备尺寸为1280 x 720,则会显示以下内容:
For example if the device dimension is 1280 x 720, it would result in the following:
Flex: 纵向模式高度= 1280. 横向模式高度= 720
Flex: portrait mode height = 1280. Landscape mode height = 720
窗口: 纵向模式高度= 1280. 横向模式高度= 1280
Window: portrait mode height = 1280. Landscape mode height = 1280
在安装组件时,Window会检索一次尺寸.是的,您可以在屏幕旋转时手动为窗口添加检测器,但我不明白为什么在Flex短而简单的情况下您要花费那么多的精力.
Window retrieves your dimensions once when the component mounts. Yes you can manually add detectors for window when a screen rotates, but i don't see why you want to go through that much effort when flex is short and simple.
这篇关于React Native:身高vs屈曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!