带有 CollapsingToolbarLayout 的状态栏下的 MapView

MapView under statusbar with CollapsingToolbarLayout

我有以下 XML 代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/abl_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/ctl_header"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            android:fitsSystemWindows="true"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

            <fragment
                android:id="@+id/map"
                android:name="com.google.android.gms.maps.SupportMapFragment"
                xmlns:map="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="280dp"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"
                app:layout_collapseParallaxMultiplier="0.5"
                map:cameraZoom="15"
                map:liteMode="true"
                map:mapType="normal"/>


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:elevation="@dimen/spacing_tiny"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>


    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab_pin"
        style="@style/FabStyle"
        app:layout_anchor="@id/abl_header"
        app:layout_anchorGravity="bottom|right|end"/>

</android.support.design.widget.CoordinatorLayout>

我想在状态栏下方绘制 MapView(此处为片段),如下图所示:

但是我得到了以下结果:

但是当滚动时,MapView 正确绘制在状态栏下方,如下图所示:

并且因为在使用 ImageView 而不是片段时这是有效的,我猜这是因为在构建片段时测量错误。

我想知道除了在将位图注入 ImageView 之前创建 MapView 和从代码创建位图之外是否还有其他解决方案。

我知道怎么解决了。

而不是从布局文件本身创建 MapView 片段。 我创建了 SupportMapFragment 并使用经典片段事务将其添加到视图中。

这样我就得到了正确的渲染。