2017-05-06 95 views
0

我想將字符串'example'放在標題中間。對齊左側的後退按鈕和中間的文字

enter image description here

代碼:

<View style={viewStyle}> 
     <ImageButton 
     imageUrl={require('./assets/icons/Back-25.png')} 
     onPress={props.onPressPhone} 
     /> 
     <Text>{props.headerText}</Text> 
    </View> 

viewStyle:

backgroundColor: 'white', 
    alignItems: 'center', 
    height: 60, 
    paddingTop: 15, 
    shadowColor: '#000000', 
    shadowOffset: { width: 0, height: 1 }, 
    shadowOpacity: 0.2, 
    elevation: 2, 
    position: 'relative', 
    flexDirection: 'row', 
    justifyContent: 'space-between', 

圖片按鈕風格:

alignSelf: 'center', 

回答

0

一種方式做,這是使用相同尺寸的空的.png我法師的另一面和空間之間在頭造型:和

<View style={ styles.header }> 
    <Button style={{left: 10}} onPress={() => this.handlePress() }> 
     <Image source={ require('../images/arrow_back.png') } style={{ width: 50, height: 50 }} /> 
    </Button> 
    <Text style={styles.header_text} >{this.props.title}</Text> 
    <Button style={{right: 10}}> 
     <Image source={ require('../images/no_image.png') } style={{ width: 50, height: 50 }} /> 
    </Button> 
</View> 

header: { 
    flex: 1, 
    flexDirection: 'row', 
    alignItems: 'center', 
    justifyContent: 'space-between', 
    width: width, 
    backgroundColor: '#09146d', 
}, 

...有點缺憾,但它已經爲我工作。或者,您可以瓜分頭與基於Flex的意見,使用flexDirection: 'row'

View style={ styles.header }> 
    <View style={{flex: 1}}> 
     //Button in here 
    </View> 
    <View style={{alignItems: 'center', flex: 6}}> 
     //Text in here 
    </View> 
    <View style={{flex: 1}}> 
     //Nothing in here 
    </View> 
</View> 

祝你好運!

相關問題