[英]React-Native flex-box overlap min height required?
So I have a pretty good understanding of flexbox but this same issue always seems to keep popping up for me so I figured I'd post it in order to put it to rest once and for all... 所以我对flexbox有一个很好的理解,但同样的问题总是似乎不断出现在我身上所以我想我会发布它以便让它一劳永逸地休息......
In flexbox I try to stack items in a ScrollView like so: 在flexbox中,我尝试在ScrollView中堆叠项目,如下所示:
1 1
2 2
3 3
but my results turn out a bit like this: 但我的结果有点像这样:
1 1
2 3 2 3
where 2 and 3 sort of overlap. 其中2和3种重叠。 I don't understand why this occurs but I can fix it if I define a height.
我不明白为什么会这样,但如果我定义一个高度,我可以解决它。 My issue with defining a height is that it is fixed and not variable across screen sizes so how can I get around hard coding a height.
我定义高度的问题在于它是固定的,并且在屏幕尺寸上不可变,因此我如何绕过硬编码高度。 See code examples / screenshots below.
请参阅下面的代码示例/屏幕截图。
<ScrollView style={{flex: 0.8, flexDirection: 'column',}}>
<View style={{ flex: 0.2, height: 250 }}>
<Swiper
cards={['DO', 'MORE', 'OF', 'WHAT', 'MAKES', 'YOU', 'HAPPY']}
renderCard={card => (
<View style={styles.card}>
<Text style={styles.text}>{card}</Text>
</View>
)}
onSwiped={(cardIndex) => { console.log(cardIndex); }}
onSwipedAll={() => { console.log('onSwipedAll'); }}
cardIndex={0}
stackSize={3}
backgroundColor="#fff"
/>
</View>
<View style={{ flex: 0.5 }}>
<Text
h3
style={{
color: '#161616', fontWeight: 'bold', textAlign: 'center', paddingTop: scale(15),
}}
>
Case Information
</Text>
</View>
</ScrollView>
As you see in the code above I have height defined as 250. With the height defined I get an output like this (what I want): 正如你在上面的代码中看到的那样,我将高度定义为250.定义了高度后,我得到一个像这样的输出(我想要的):
Without the height: 250 I get an output like this: 没有高度:250我得到这样的输出:
Again I don't want the height 250 in there because it could vary per screen size is there a good way to fix this issue? 我再次不希望那里的高度250,因为它可能因屏幕大小而异,是否有解决此问题的好方法? Also note I am using react-native-deck-swiper for the swiper component.
另请注意,我使用react-native-deck-swiper作为swiper组件。
You don't need to hard code the height. 您不需要硬编码高度。 You can get of the screen on which you app is running by using the code below.
您可以使用以下代码获取运行应用程序的屏幕。
import {Dimensions} from 'react-native';
const {height, width} = Dimensions.get('window');
Then you can provide height like: 然后你可以提供如下高度:
<View style={{ flex: 0.2, height: height*0.5 }}>
In the case above, the height will be 50%
of the height of your mobile's screen. 在上面的情况中,高度将是移动设备屏幕高度的
50%
。 Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.