【问题标题】:Cannot move button inside react native maps无法在反应原生地图中移动按钮
【发布时间】:2018-07-12 09:22:11
【问题描述】:

我正在尝试在我的地图组件中移动一个按钮。我正在使用 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,
  },
});

在这种情况下,我的按钮位于地图的中心/顶部,我想将其移动到地图的中心/右侧

有什么想法吗? 谢谢

【问题讨论】:

    标签: javascript react-native react-native-maps


    【解决方案1】:

    首先关闭 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-04
      • 2021-01-01
      相关资源
      最近更新 更多