react-native - 如何将 ActivityIndicator 中心放置到视图中
问题描述
我是 react-native 的新手,实际上我制作了一个登录组件页面,每当用户按下登录时,我都必须显示活动指示器。但这里我的问题是视图包含列方向的一些组件,我该如何放置它。
代码:
<ImageBackground style={styles.imageStyle} source={require('../images/splash_background_landscape.png')}>
<View style={styles.loadingStyle}>
<ActivityIndicator></ActivityIndicator>
</View>
<View style={styles.parentViewStyle}>
</View>
</ImageBackground>
parentViewStyle: {
flex: 1,
marginTop: 20,
},
loadingStyle : {
flex :1
justifyContent : 'center',
alignItems : 'center'
}
解决方案
创建一个新类,hudView.js
并将其重新用于所有加载屏幕,
import React, { Component } from "react";
import { View, ActivityIndicator } from "react-native";
export default class hudView extends Component {
constructor(props) {
super(props);
}
render() {
return (
<View
style={{
position: "absolute",
top: 0,
bottom: 0,
left: 0,
right: 0,
alignItems: "center",
justifyContent: "center",
backgroundColor: "rgba(110,110,110,0.5)"
}}
>
<View
style={{
width: 100,
height: 100,
backgroundColor: "transparent", //"rgba(255,255,255,1)",
alignItems: "center",
justifyContent: "center",
borderRadius: 5,
overflow: "hidden"
}}
>
<ActivityIndicator size="large" color="red" />
</View>
</View>
);
}
}
并在你的课堂上使用它,
例如:
...
import HudView from "../../components/hudView";
...
render() {
return(
...
...
{this.state.isLoading ? <HudView ref={"hudView"} /> : null}
)
}
推荐阅读
- google-sheets - Zoho creator 在尝试将 creator-form-data 集成到谷歌表格时收到无效的 JSON 有效负载
- powershell - 获取 PSObject 数组大小或计数
- python - pipenv --docker 的系统选项。在 docker 中获取所有 python 包的建议方法是什么
- conceptnet - 与调优相关的概念网
- canvas - 如何在three.js中制作纹理网格对象灰度?
- c# - 如何对中间显示消息框的 Windows 窗体方法进行单元测试
- android - Firebase 侦听器跳过
- java - 按字段的日期对 Array 对象进行排序
- php - 显示具有不同颜色的记录
- python-3.x - n_jobs = -1 等效于 keras