Cos*_*ure 2 css activity-indicator react-native
我正在使用视图叠加和 ActivityIndicator 在后台隐藏加载地图。我使用的解决方案是具有绝对位置的 View ,使其位于所有内容之上,并将 ActivityIndicator 放在顶部,因此会发生一些事情。问题是,因为 ActivityIndiator 大小无法设置为 iOS 上的特定像素,所以我不知道它的大小是多少,因此我无法将其正确居中。或者我没有找到方法来做到这一点。
这是一些代码:
<View style={styles.whiteOverlay}>
<ActivityIndicator style={styles.indicator} size="large" color={colors.color4} />
</View>
whiteOverlay: {
width: screen.height,
height: screen.height,
backgroundColor: 'white',
position: 'absolute',
zIndex: 20
},
indicator: {
zIndex: 21,
position: 'absolute',
left: screen.width/2,
top: screen.height/2
}
Run Code Online (Sandbox Code Playgroud)
这使得指示器偏离中心。我可以在那里放置一些神奇的数字,使其适用于特定设备,猜测指示器的大小,但它不适用于其他设备。谢谢你的帮助。
如果你想让ActivityIndicator在屏幕上居中,你可以这样设置样式。
<View style={{ flex: 1, alignItems: "center", justifyContent: "center", zIndex: 20 }}>
<ActivityIndicator
size="large" color={colors.color4}
/>
</View>
Run Code Online (Sandbox Code Playgroud)
或者你可以使用样式position
<View style={styles.whiteOverlay} >
<ActivityIndicator
size="large" color={colors.color4}
/>
</View >
...
whiteOverlay: {
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
alignItems: 'center',
justifyContent: 'center'
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3411 次 |
| 最近记录: |