Android 如何设置覆盖内容的AppBarLayout?

Android 如何设置覆盖内容的AppBarLayout?,android,android-layout,android-coordinatorlayout,android-appbarlayout,Android,Android Layout,Android Coordinatorlayout,Android Appbarlayout,这是我当前的XML: <android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent"

这是我当前的XML:

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include layout="@layout/some_layout" />

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>


现在“some_layout”位于“recycler_视图”上方,并与它一起滚动。我想改变它,使“some_布局”覆盖在recycler视图上,但滚动行为仍然存在(基本上,当没有滚动时,两个视图都应该顶部对齐,“some_布局”应该在滚动后消失)。可以使用CoordinatorLayout吗?

如果我正确理解了您的问题,您希望
Appbar
覆盖您的内容(
RecyclerView
),对吗

虽然我还没有验证这个解决方案,但它是基于。让我知道这是否有效


通过新建
MyAppBarScrollingViewBehavior
覆盖
onDependentViewChanged()
并将
updateOffset()
修改为
offset=0

@Override
public boolean onDependentViewChanged(CoordinatorLayout parent, View child,
        View dependency) {
    updateOffset(parent, child, dependency);
    return false;
}

private boolean updateOffset(CoordinatorLayout parent, View child,
        View dependency) {
    final CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) dependency
            .getLayoutParams()).getBehavior();
    if (behavior instanceof Behavior) {
        // Offset the child so that it is below the app-bar (with any
        // overlap)
        final int offset = 0;   // CHANGED TO 0
        setTopAndBottomOffset(offset);
        return true;
    }
    return false;
}
在RecyclerView上设置行为

<android.support.v7.widget.RecyclerView
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    ...
    layout_behavior="MyAppBarScrollingViewBehavior" />