简体   繁体   English

使 ScrollView - 项目使用整个屏幕的百分比大小

[英]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.

相关问题 如何使此弹出窗口的宽度占用户屏幕大小的百分比? - How to make the width of this popup a percentage of the user's screen size? 使按钮成为任何屏幕尺寸或缩放百分比的另一个元素的结尾 - Make a button to be end of another element at any screen size or zoom percentage 如何使 ScrollView 组件的大小与 React Native 中的屏幕大小成比例? - How Do I Make ScrollView Components Size a Ratio of Screen Size in React Native? 如何使已加载项目的数量与屏幕尺寸有关? - How to make number of loaded items related to the screen size? 使图像占屏幕的百分比而不是像素? - make the Image a percentage of the screen and not pixels? 堆叠使用百分比大小的图像 - Stack images that use percentage size 在将浏览器屏幕重新调整为大尺寸时,在浏览器移动屏幕尺寸中切换导航图标将使导航列表项消失 - Toggling nav icon in browser mobile screen size will make nav-list-items dissapear when readjusting browser screen to large size firefox扩展如何使用3D格式的整个屏幕(例如CoolIris)? - How do firefox extensions make use of the whole screen in 3D (eg. CoolIris)? REACT NATIVE:如何为整个屏幕制作抽屉 - REACT NATIVE: How to make Drawer for whole screen 如何使我的应用适合整个屏幕 - How to make my app fit the whole screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM