• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - React Native 响应式 View Iphone x

[复制链接]
菜鸟教程小白 发表于 2022-12-11 22:06:14 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

  <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%')
    },

});

输出 enter image description here



Best Answer-推荐答案


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

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

在下面,您可以看到 2 touchableopacitys 的 View 。它们不应该重叠。其实试试在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>

关于ios - React Native 响应式 View Iphone x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54389044/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap