为什么textAlign:'center'不能在react-native中工作?

时间:2016-05-23 04:03:29

标签: reactjs react-native react-router

如何使标签水平居中。我使用textAlign:'center'。但它不起作用。我的代码是 https://rnplay.org/apps/ZN2gvA

'use strict';

import React from 'react-native';
const {
  AppRegistry,
  Component,
  Text,
  View

}=React;

const styles=React.StyleSheet.create({
  container:{
    paddingTop:20,
     textAlign:'center',

  },
  label:{
   color:'blue',
   backgroundColor:'red'   

}
})

class SampleApp extends Component{
  render(){

    return (<View style={styles.container}><Text style={styles.label}>hello</Text></View>)
  }

}
AppRegistry.registerComponent('SampleApp', () => SampleApp);

1 个答案:

答案 0 :(得分:2)

你应该多关注React Native给你的警告:

enter image description here

样式textAlign: 'center'仅适用于Text个组件。请查看ViewText的样式文档。

在您的情况下,从textAlign: 'centre'移除container并将其添加到label。查看我在https://rnplay.org/apps/RQX5Fw

所做的更改