[英]Make ScrollView - Items use a percentage size of the whole screen
My current scrollview items have the problem, that I need to set a fixed height and width for them in order to show up properly on different devices.我当前的滚动视图项目有问题,我需要为它们设置固定的高度和宽度,以便在不同的设备上正确显示。
Every scrollview item should use 1/6 of the screen height in order to fit for different screen sizes... but how do we achieve this without making the scrollview unscrollable ?每个滚动视图项都应该使用屏幕高度的 1/6 以适应不同的屏幕尺寸……但是我们如何在不使滚动视图不可滚动的情况下实现这一点?
My current attempt...我目前的尝试...
<ScrollView style={{backgroundColor: 'blue'}} contentContainerStyle={{flexGrow: 1}}>
{ /* Renders the header */}
<Header text={Constants.header} screen="Drills&Games"/>
<BoxView></BoxView>
<BoxView></BoxView>
<BoxView></BoxView>
<BoxView></BoxView>
<BoxView></BoxView>
</ScrollView>
export default class BoxView extends Component{
render(){
return(
<View style={{backgroundColor: 'red', flex: 0.25}}>
</View>
);
}
}
Renders a scrollview with 5 BoxView-Items... The problem here is... the box views do scale correctly, each one uses 0.25 flex, but the list is not scrollable anymore.渲染带有 5 个 BoxView-Items 的滚动视图......这里的问题是......框视图正确缩放,每个使用 0.25 flex,但列表不再可滚动。
So how do we pass a percentage/flex height to the items with keeping the scrollview scrollable ?那么我们如何在保持滚动视图可滚动的情况下将百分比/弹性高度传递给项目?
On react native I recommend using Dimensions on setting dynamic height.在 React Native 上,我建议使用Dimensions来设置动态高度。
for getting the 1/6 of the screen I would do is为了获得屏幕的 1/6,我会做的是
{ height: Dimensions.get("screen").height * 0.16 }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.