2

我有以下 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 正确绘制在状态栏下方,如下图所示: 滚动时在下方绘制的 MapView

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

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

4

1 回答 1

2

我想出了如何解决这个问题。

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

这样,我就有了正确的渲染。

于 2016-04-16T20:00:59.697 回答