ReactNative: how to center text?

前端 未结 16 730
终归单人心
终归单人心 2020-12-22 18:40

How to center Text in ReactNative both in horizontal and vertical?

I have an example application in rnplay.org where justifyContent=\"center\" and

相关标签:
16条回答
  • 2020-12-22 19:12

    Horizontal and Vertical center alignment

    <View style={{flex: 1, justifyContent: 'center',alignItems: 'center'}}>
         <Text> Example Test </Text>
    </View>
    
    0 讨论(0)
  • 2020-12-22 19:14

    first add in parent view flex:1, justifyContent: 'center', alignItems: 'center'

    then in text add textAlign:'center'

    0 讨论(0)
  • this is a example for Horizontal and Vertical alignment simultaneously

    <View style={{width: 200, flexDirection: 'row',alignItems: 'center'}}>
         <Text style={{width: '100%',textAlign: 'center'}} />
    </View>
    
    0 讨论(0)
  • 2020-12-22 19:16

    The following property can be used: {{alignItems: 'center'}}

    <View style={{alignItems: 'center'}}>
     <Text> Hello i'm centered text</Text>
    </View>
    
    0 讨论(0)
  • 2020-12-22 19:18

    used

    textalign:center

    at the view

    0 讨论(0)
  • 2020-12-22 19:20

    Wherever you have Text component in your page just you need to set style of the Text component.

     <Text style={{ textAlign: 'center' }}> Text here </Text>
    

    you don't need to add any other styling property, this is spectacular magic it will set you text in center of the your UI.

    0 讨论(0)
提交回复
热议问题