RecyclerView隐藏在AppbarLayout后面?

时间:2017-03-15 12:55:08

标签: android android-fragments

我有一个带有CoordinatorLayout的Activity,里面有一个FrameLayout作为片段容器。我使用工具栏并更改可见性和FitSystemWindows属性来控制Appbar Overlay,如下所示:

private void modifyToolbar(boolean isVisible) {
    if (isVisible) {
        appbar.setFitsSystemWindows(true);
        imageToolBar.setVisibility(View.VISIBLE);
        imageToolBar.setFitsSystemWindows(true);
        coll.setFitsSystemWindows(true);
        appbar.requestApplyInsets();
    } else {
        appbar.setFitsSystemWindows(false);
        imageToolBar.setVisibility(View.GONE);
        imageToolBar.setFitsSystemWindows(false);
        coll.setFitsSystemWindows(false);
        appbar.requestApplyInsets();
    }
}

它工作正常,除非在我的叠加片段中,我折叠叠加ImageView并返回到非叠加片段然后返回。叠加项将隐藏在工具栏后面。

正常:

enter image description here

错误:

enter image description here

这是我的活动和我的appbar

    <?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.phoenix.soft.agenda.MainActivity">

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|start"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/ic_add_white_24dp"
        app:backgroundTint="@drawable/fab_background"
        app:layout_anchor="@+id/fragment_content"
        app:layout_anchorGravity="bottom|right" />

        <FrameLayout
            android:id="@+id/fragment_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:behavior_overlapTop="64dp"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
             />
</android.support.design.widget.CoordinatorLayout>

Appbar:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="false"
    android:theme="@style/AppThemeNew.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/coll_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/primary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:titleEnabled="false">

        <ImageView
            android:id="@+id/image_over_lay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:src="@drawable/find_bank"
            android:transitionName="@string/toolbar_transition"
            android:visibility="gone"
            app:layout_collapseMode="parallax" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_bar"
            android:visibility="gone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppThemeNew.PopupOverlay" />


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


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

而且,当我崩溃AppBar并返回时,会出现“眨眼”。我想这也是导致这个问题的原因。 谢谢你的帮助。

0 个答案:

没有答案