如何将文本放在标记的顶部并将其对齐居中?

问题描述 投票:0回答:1

我试图在标记的顶部放置一个文本并将其对齐居中。出于某种原因,我无法将其移动到比图片中更多的位置。而且它没有居中。

<Marker.Animated

  ref={marker => { this.marker = marker; }}
  image={avatars[this.userData.avatar]}

  coordinate = {{
    latitude: this.state.playerLocation.latitude,
    longitude: this.state.playerLocation.longitude
}}      
title={this.userData.userName}
    >
    <View style={{justifyContent:'center',alignContent:'center'}}>
    <Text style={{textAlign:'center',color:'white',margionTop:-20}}>{this.userData.userName}</Text>

    </View>

    </Marker.Animated>

enter image description here

react-native react-native-maps
1个回答
0
投票

添加flex:1

<View style={{
             flex:1,
             justifyContent:'center',
             alignContent:'center',
           }}
        >
    <Text style={{
            flex:1,
            textAlign:'center',
            color:'white',
            margionTop:-20
        }}
    >{this.userData.userName}</Text>

</View>
© www.soinside.com 2019 - 2024. All rights reserved.