RecyclerView 盖住 AppBarLayout 问题解决

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Rec_Mervyn/article/details/76791482

初学Android,前几天学到Material Design,非常喜欢这个UI。迫不及待就用MD设计尝试写了个App。
然后在开发过程中遇到了些问题。

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    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.support.v7.widget.Toolbar
            android:id="@+id/toobar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

        <!--其他控件-->

    </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"
        android:layout_marginTop="30dp"/>

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

一开始敲上述代码运行时发现RecyclerView盖住了AppBarLayout的除了Toolbar的其他控件。
查书后解决,应给RecyclerView指定一个布局行为,在其tag中添加下述代码。
app:layout_behavior="@string/appbar_scrolling_view_behavior"
即可解决。

猜你喜欢

转载自blog.csdn.net/Rec_Mervyn/article/details/76791482