【问题标题】:Buttons will not align in center of screen按钮不会在屏幕中心对齐
【发布时间】:2019-08-07 17:04:37
【问题描述】:

我正在尝试将我的按钮对齐到中心,但我拥有它的方式不会这样做。我在我的容器中将它们设置为“中心”,并且我还为样式表中的每个属性都这样做了。有人知道它可能是什么吗?

这是我在渲染中的设置:

<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>

这就是我设置样式表的方式:

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
  }
});

【问题讨论】:

    标签: react-native stylesheet


    【解决方案1】:

    好吧,你忘了把对齐属性放在ImageBackground

    这里是博览会link

    【讨论】:

    • 很高兴它有帮助。继续编码!
    猜你喜欢
    • 2016-11-14
    • 2014-03-26
    • 2019-03-25
    • 2023-01-23
    • 1970-01-01
    • 1970-01-01
    • 2015-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多