【问题标题】:React Native Responsive View Iphone xReact Native 响应式视图 Iphone x
【发布时间】:2019-01-27 14:13:18
【问题描述】:

我在为 Iphone X 设计样式时遇到了一个小问题,我使用了 react-native-responsive-screen 中的 widthPercentageToDP 和 heightPercentageToDP 来使视图相似,在除 Iphone X 之外的大多数设备中它都可以正常工作,差异有点有点,但我想让视图尽可能准确。

  <View style={styles.container}>
                <ImageBackground source={require('../../assets/acc.png')} style={styles.bgImg}>
                    <View style={styles.headerView}>
                    <FontAwesome style={styles.setting}  name="cog" size={hp('4%')} color="#6B6466" />
                    <Text style={styles.headerText}>My Account</Text>
                    </View >

                    <View style={styles.imgView} >
                        <Image source={require('../../assets/user.png')} style={styles.accImg}/>
                        <Text style={styles.name}> John doe</Text>
                        <Text style={styles.number}> 123456789</Text>
                    </View>
                    <View style={styles.bottomView}>
                    <View style={styles.bottomView2}>

                        <TouchableOpacity style={styles.inboxView}>
                            <Text style={styles.inboxNumber}>12</Text>
                            <Text style={styles.inboxText}>Inbox</Text>
                        </TouchableOpacity>
                        <TouchableOpacity style={styles.inboxView}>
                            <Text style={styles.inboxNumber}>17</Text>
                            <Text style={styles.inboxText}>Sent</Text>
                        </TouchableOpacity>
                    </View>
                    </View>
                </ImageBackground>
            </View>

风格

const styles = StyleSheet.create({
    container: {
        flex: 1, backgroundColor: '#fff'
    },
    bgImg:{
        height: hp('40%'), width: '100%'
    },
    setting:{
        color:'white'
    },
    headerText:{
        flex:1,textAlign:'center',fontSize:wp('5%'),fontFamily:Fonts.Cairo,marginRight:10,color:'white'
    },
    headerView:{
        flexDirection:'row',justifyContent:'space-between',marginHorizontal:10,marginTop:hp('5%')
    },
    imgView:{
        flex:1,
        alignItems:'center'
    },
    accImg:{
        height:wp('30%'),width:wp('30%'),borderRadius:wp('15%'),marginTop:wp('3%')
    },
    name:{
        color:'white',fontFamily:Fonts.Cairo,fontSize:wp('4%'),textAlign:'center'
    },
    number:{
        color:'white',fontSize:wp('4%'),textAlign:'center'
    },
    bottomView:{
        flex:1,
        justifyContent:'flex-end'
    },
    inboxNumber:{
        color:'white',
        textAlign:'center',
        fontSize:wp('4%')
    },
    inboxText:{
        color:'white',
        textAlign:'center',
        fontSize:wp('4%'),
        fontFamily:Fonts.Cairo
    }, 
    bottomView2:{
        flexDirection:'row',
        justifyContent:'space-between',
        marginHorizontal:10,
        marginBottom:wp('3%')
    },

});

输出

【问题讨论】:

  • 有一个内置组件可以帮助您做到这一点:SafeAreaView

标签: ios react-native responsive-design-view


【解决方案1】:

Iphone X 正在渲染真实的结果,这就是您的布局的样子,其他设备没有足够的空间进行渲染,并且它们“重叠”了视图...看看您的视图,您有一个图像背景它占据了 40% 的屏幕,里面有一个可以正常渲染的标题,因为它在渲染功能中更高。

下面你有一个带有 flex :1 的视图和一个基于屏幕值的图像,下面有 2 行文本,如果图像大于视图,它将把文本推到视图之外,侵入下面的邻居视图

在下面,您可以看到 2 touchableopacitys 的视图。它们不应该重叠。其实试试在imgView样式里加overflow:'hidden'

------标题------

///////图片////////

///////图片////////

///////约翰多///////

///////12345////////

按钮//////按钮

就像 iphone 显示的那样

<ImageBackground source={require('../../assets/acc.png')} style={styles.bgImg}>
                    <View style={styles.headerView}>
                    //here is the header
                    </View >

                    <View style={styles.imgView} >
                       // below is the image , the name , and the number
                    </View>
                    <View style={styles.bottomView}>
                    //below it should be the 2 buttons , not overlapping, BELOW
                    </View>
                </ImageBackground>

【讨论】:

  • 嗨 Valda,如果你注意到我使用 widthPercentageToDP 和 heightPercentageToDP 根据设备大小缩放所有内容,所以我想它们应该具有相同的缩放比例
  • 在编辑中,我发布了您的观点,以及它们的实际情况,不应该重叠。尝试将 overflow:'hidden' 放入 styles.headerView 、 styles.imgView 和 styles.bottomView 以查看哪个重叠/超出其视图
猜你喜欢
  • 2019-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-02
  • 2016-02-11
  • 2018-01-16
相关资源
最近更新 更多