React Native中如何快速使一个元素相对屏幕水平居中,垂直居中

alignItems:决定其子元素沿着侧轴(次轴)的排列方式
justifyContent:决定其子元素沿着主轴的排列方式
width和height:react native指定宽高,其值不能带有单位,纯数字
实现效果如下——使元素相对屏幕水平居中,垂直居中:
在这里插入图片描述
代码:

import React from 'react'
import {ActivityIndicator, StyleSheet, Text, View} from 'react-native'

export default class LoadingIcon extends React.Component{
    render(){
        const {color} = this.props//通过父组件传递过来,控制loading icon和字体颜色
        return (
            <View style={style.loadWrap}>
                <ActivityIndicator size={'large'} color={color}/>
                <Text style={{color:color}}>数据获取中...</Text>
            </View>
        )
    }
}
//react native中width和height是不能有单位的,但是可以通过引号来实现宽高100%占比
const style = StyleSheet.create({
    loadWrap:{
        alignItems: 'center',
        justifyContent: 'center',
        backgroundColor:'white',
        height:'100%',
        width: '100%'
    }
})

拓展:可以实现dialog对话框和自定义toast

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值