无法在React Native Maps中移动按钮

3

我将尝试在我的地图组件中移动一个按钮。我正在使用react-native-maps。

让我展示给你我的代码:

render() {
console.log(this.state)
const { region } = this.state;
return (
  <View style={styles.container}>
    <MapView
      provider={this.props.provider}
      mapType="standard"
      style={styles.map}
      showsUserLocation={true}
      initialRegion={region}
    > 
      <UrlTile
        urlTemplate="XXX"
        zIndex={-1}
      />
      <Button style={{ borderWidth: 2, alignItems:'right',justifyContent:'right'}} title="Info" onPress={() => console.log("This is not fired")}/>
    </MapView>
    <View>
    </View>
  </View>
);
}
}


 const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  map: {
    marginTop: 20,
    flex: 1,
  },
});

在这种情况下,我的按钮位于地图的中心/顶部,我想将它移动到地图的中心/右侧。 有什么想法吗? 谢谢。
1个回答

12

首先关闭MapView组件,然后将按钮放在其下方,就像这样:

<View style={{ flex: 1 }}>
<MapView
    style={{ flex: 1 }}
/>
<View
    style={{
        position: 'absolute',//use absolute position to show button on top of the map
        top: '50%', //for center align
        alignSelf: 'flex-end' //for align to right
    }}
>
    <Button />
</View>


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接