fitsSystemWindows AppBarLayout RecyclerView отклоняет при повторном посещении фрагмента - PullRequest
0 голосов
/ 24 октября 2018

Ниже приведен мой макет xml

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="245dp"
    android:background="@android:color/transparent"
    android:fitsSystemWindows="true"
    app:layout_behavior="com.gmr.android.FixAppBarLayoutBehavior">

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


        <ImageView
            android:id="@+id/imgAirportBg"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:src="@drawable/screen_bg"
            android:tint="#8a000000"
            android:visibility="visible"
            app:layout_collapseMode="parallax" />


        <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:elevation="2dp"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"
            app:title="@string/empty"
            app:contentInsetStartWithNavigation="0dp"
            app:layout_behavior=".view.ToolbarBackgroundAlphaBehavior"
            app:layout_collapseMode="pin"
            app:logo="@drawable/toolbar_logo"
            app:navigationIcon="?attr/homeAsUpIndicator"
            app:theme="@style/TransperantToolbar" />

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


<android.support.v7.widget.RecyclerView
    android:id="@+id/home_recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:descendantFocusability="beforeDescendants"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:layoutAnimation="@anim/layout_animation_recycler_slide_in"
    android:paddingBottom="?attr/actionBarSize"
    app:behavior_overlapTop="40dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />


<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <include
        android:id="@+id/llNoConnection"
        layout="@layout/no_connection_layout"
        android:visibility="gone" />

    <ProgressBar
        android:id="@+id/progBar"
        style="?android:attr/progressBarStyle"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:visibility="gone" />
</FrameLayout>

Ниже приведена активность xml

<?xml version="1.0" encoding="utf-8"?>

<com.gmr.android.custom.FitsSystemWindowsFrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/mwhite"
        android:elevation="2dp"
        android:visibility="gone"
        app:navigationIcon="?attr/homeAsUpIndicator" />

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true" />


    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="@color/bottom_nav_view_color"
        app:itemIconTint="@color/bottom_nav_view_icon_tint_selector"
        app:itemTextColor="@color/bottom_nav_view_text_color"
        app:menu="@menu/navigation" />
</com.gmr.android.custom.FitsSystemWindowsFrameLayout>


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

Добавлен следующий код в Activity oncreate для устранения проблемы, перекрывающей панель инструментов Android с панелью состояния

public void setWinowInsetsFramentContianer() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        findViewById(R.id.main_content).setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
            @Override
            public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
                ViewGroup viewGroup = (ViewGroup) view;
                boolean consumed = false;
                for (int i = 0; i < viewGroup.getChildCount(); i++) {
                    View child = viewGroup.getChildAt(i);
                    WindowInsets childResult = null;
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
                        childResult = child.dispatchApplyWindowInsets(windowInsets);
                    }
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        if (childResult.isConsumed()) {
                            consumed = true;
                        }
                    }
                }
                if (consumed) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
                        return windowInsets.consumeSystemWindowInsets();
                    }
                } else {
                    return windowInsets;
                }
                return windowInsets;
            }

        });
    }
}

Мой RecyclerView исчезает при повторном просмотре фрагмента, если я удаляю android: fitsSystemWindows = "true " все работает нормально, это происходит после того, как я обновил библиотеку поддержки до 27.1.1 , до этого она работала нормально

...