不知何故 position: 'absolute'
在 Android 中不工作。它适用于 iOS,但在 Android 中它不呈现。有人知道如何在 Android 设备上设置 position: "absolute"吗?
Button: {
position: "absolute",
right: 0,
top: 0,
borderRadius: 4,
borderWidth: 2,
width: 100,
height: 40,
borderColor: 'red',
backgroundColor: "rgb(72, 120, 166)",
}
最佳答案
将 Button 包装在 View 中适用于 Android 和 iOS:
import React, { Component } from 'react';
import { Text, View, StyleSheet, Button } from 'react-native';
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<View style={styles.buttonView}>
<Button style={styles.button} title={"Click"}/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
},
buttonView: {
position: "absolute",
right: 0,
top: 0
},
button:{
borderRadius: 4,
borderWidth: 2,
width: 100,
height: 40,
borderColor: 'red',
backgroundColor: "rgb(72, 120, 166)",
}
});
关于android - React Native - 位置 "absolute"在 Android 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51190180/