提问者:小点点

在样式表中将水平线移动到中心


我画了一条这样的水平线。 但是,它会朝屏幕左侧显示。 我不想增加宽度。 不然怎么把它移到中心? 我尝试用另一个视图和alignContent一起包装它:“center”等,但它对我不起作用。

<View style={styles.horizontalLine}></View>
  horizontalLine: {
    marginTop: 25,
    width: '80%',
    height: 1,
    //alignContent: 'center',
    //width: 1,
    backgroundColor: '#E0E0E0',
  },


共3个答案

匿名用户

添加一个alignself:'center',如下所示

         horizontalLine: {
            marginTop: 25,
            width: '80%',
            height: 1,
            //alignContent: 'center',
            //width: 1,
            alignSelf: 'center',
            backgroundColor: '#E0E0E0',
          }

匿名用户

您可以提供水平边距:auto

horizontalLine: {
  // ...
  marginLeft: 'auto',
  marginRight: 'auto',
  // ...
},

匿名用户

试试这个。。。

水平:{margin:'auto',margintop:25,width:'80%',height:1,backgroundcolor:'#e0e0e0',}