其他分享
首页 > 其他分享> > Android – 隐藏在AppBarLayout后面的视图

Android – 隐藏在AppBarLayout后面的视图

作者:互联网

我有问题,我的RecyclerView在AppBarLayout后面被切断了

enter image description here

这是我的XML

<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.MainActivity">

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

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_tool_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:color="@android:color/white"
            app:contentScrim="@color/blue_grey_900"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ProgressBar
                android:id="@+id/loadingProgressBar"
                android:layout_width="wrap_content"
                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:layout_scrollFlags="snap|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>

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


    <android.support.v7.widget.RecyclerView
        android:id="@+id/rvList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical" />


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/activity_vertical_margin"
        android:src="@android:drawable/ic_menu_share"
        app:layout_behavior="irisrecognition.example.com.irisrecognition.adapter.ScrollAwareFABBehavior" />

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

<android.support.design.widget.NavigationView
    android:id="@+id/navigation_drawer"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:menu="@menu/menu_main" />

解决方法:

您忘了指定RecyclerView的layout_behavior.添加此行

app:layout_behavior="@string/appbar_scrolling_view_behavior"

到您的RecyclerView的XML:

<android.support.v7.widget.RecyclerView
    android:id="@+id/rvList"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

标签:android-appbarlayout,android,android-layout
来源: https://codeday.me/bug/20190722/1503424.html