代码之家  ›  专栏  ›  技术社区  ›  Akash Salunkhe

React Native map,map下面的组件显示在map上面而不是下面

  •  0
  • Akash Salunkhe  · 技术社区  · 6 年前

    ContactComponent-(在我使用map组件的地方,在它下面要显示其他组件)

      render() {
        return (
          <View style={styles.container}>
            <MapComponent />
            <Text>Akas</Text>
          </View>
        );
      }
    

    地图组件-

        render() {
        return (
          <View style={styles.container}>
            <MapView
              provider={PROVIDER_GOOGLE} // remove if not using Google Maps
              style={styles.map}
              initialRegion={{
                latitude: 19.15384,
                longitude: 72.92902,
                latitudeDelta: 0.0922,
                longitudeDelta: 0.0421
              }}
            >
              <Marker
                coordinate={{
                  latitude: 19.15384,
                  longitude: 72.92902
                }}
                title={"Hello"}
                description={"desc"}
              />
            </MapView>
          </View>
        );
      }
    }
    
    const styles = StyleSheet.create({
      container: {
        ...StyleSheet.absoluteFillObject,
        height: 200,
        width: 400,
        justifyContent: "flex-end",
        alignItems: "center"
      },
      map: {
        ...StyleSheet.absoluteFillObject
      }
    });
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Nikolay Tomitov    6 年前

    StyleSheet.absoluteFillObject basicaly是否与:

    position:absolute,
    top: 0,
    left: 0,
    ...
    

    当组件处于绝对位置时,它将从布局的正常流中分离出来(就像它在css中一样),所以不要将其用于映射。而是使用 flex:1, width: 100% 等等。

    推荐文章