【问题标题】:Map view not loading fully地图视图未完全加载
【发布时间】:2015-12-02 17:00:59
【问题描述】:

我有一个滚动视图,里面有一个相对布局,上面包含一个灵活大小的内容,下面是一个地图视图。如果整个内容的高度小于屏幕视图端口(滚动视图),我希望地图视图填充下面的剩余空间。如果整个内容大于屏幕视口,那么我希望地图视图至少具有一定的高度。这是我所做工作的精简版。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/flexContent"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_alignParentTop="true"
            android:background="#086dd9"
            android:gravity="center"
            android:text="Flexible content here"
            android:textColor="@android:color/white"
            android:textSize="22sp" />

        <com.google.android.gms.maps.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_below="@id/flexContent"
            android:background="#f73f3f"
            android:minHeight="120dp"
            map:mapType="normal"
            tools:ignore="MissingPrefix" />
    </RelativeLayout>


</ScrollView>

当整个内容的高度小于屏幕视口的高度(滚动视图的高度)时,它会按预期工作。但是,如果不是,一切正常,除了地图没有加载到地图视图的全高。请看下面的图片

内容小于滚动视图

内容大于滚动视图

正如您在第二张图片中看到的那样,地图视图本身遵守布局中设置的 minHeight 120dp 约束(我已将地图视图的背景设为红色),但实际地图并未加载到其完整高度。

如何解决这个问题?

【问题讨论】:

标签: android google-maps


【解决方案1】:

我通过将 MapView 包装在 LinearLayout 中解决了上述问题。我的最终布局现在看起来与此类似。希望它对未来的任何人都有帮助:)

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/flexContent"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:layout_alignParentTop="true"
            android:background="#086dd9"
            android:gravity="center"
            android:text="Flexible content here"
            android:textColor="@android:color/white"
            android:textSize="22sp" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true"
            android:layout_below="@id/flexContent"
            android:orientation="vertical"
            android:minHeight="120dp">

            <com.google.android.gms.maps.MapView
                android:id="@+id/mapView"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#f73f3f"
                map:mapType="normal"
                tools:ignore="MissingPrefix" />

        </LinearLayout>

    </RelativeLayout>

</ScrollView>

【讨论】:

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