首页 > 解决方案 > 在 StyledSheets 中将水平线移动到中心

问题描述

我画了一条这样的水平线。但是,它出现在屏幕的左侧。我不想增加宽度。我怎么能把它移到中心?我尝试将它与另一个视图以及 alignContent: 'center' 等一起包装,但它对我不起作用。

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

在此处输入图像描述

标签: javascriptcssreactjstypescriptreact-native

解决方案


添加一个 alignSelf:'center' 如下所示

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

推荐阅读