React native 按钮不会在屏幕中央对齐
我试着将我的按钮对准中心,但它们按我现有的方式不起作用。我在容器中将它们设置为“中心”,并且我还为样式表中的每个属性设置了中心。有人知道会是什么吗 这是我在渲染中的设置:React native 按钮不会在屏幕中央对齐,react-native,stylesheet,React Native,Stylesheet,我试着将我的按钮对准中心,但它们按我现有的方式不起作用。我在容器中将它们设置为“中心”,并且我还为样式表中的每个属性设置了中心。有人知道会是什么吗 这是我在渲染中的设置: <View style={styles.container}> <ImageBackground source={{ uri: "https://backgrounddownload.com/wp-content/uploads/201
<View style={styles.container}>
<ImageBackground
source={{
uri:
"https://backgrounddownload.com/wp-content/uploads/2018/09/simpsons-clouds-background-5.jpg"
}}
style={{ width: "100%", height: "100%" }}
>
<TouchableOpacity
onPress={() => this.props.navigation.navigate("HomerSimpson")}
style={styles.button}>
<Text style={styles.text}>Homer Simpson</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => this.props.navigation.navigate("Home")}
style={styles.button} >
<Text style={styles.text}>Home Screen</Text>
</TouchableOpacity>
</ImageBackground>
</View>
嗯,您忘记在
ImageBackground
这是一个展览嗯,你忘了在
ImageBackground
这是一个博览会很高兴它有帮助。继续编码!很高兴它有帮助。继续编码!
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
alignContent: "center"
},
text: {
fontSize: 25,
fontWeight: "bold",
color: "#f6c945",
alignItems: "center",
justifyContent: "center",
alignContent: "center",
},
button: {
flexDirection: "row",
backgroundColor: "#2d98da",
alignItems: "center",
justifyContent: "center",
alignContent: "center",
marginTop: 10,
marginBottom: 10,
borderRadius: 10,
borderWidth: 1.0,
borderColor: "black",
height: 30,
width: 260
}
});