Android RecyclerView below Toolbar

一世执手 提交于 2019-11-30 10:46:19
Hải Nguyễn

Try this:

<?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"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

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

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBarLayout"
    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"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways" />

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

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

I have removed the ViewPager and added scrolling behavior to RecyclerView

If Adding a scrolling behavior does not fix your issue

app:layout_behavior="@string/appbar_scrolling_view_behavior"

THEN TRY THIS

I had to give padding to recyclerview which is equivalent to the toolbar/actionbar(app bar) height.

  android:paddingTop="?attr/actionBarSize"  

add the above line to the recyclerview xml file

When I have included RecyclerView from another layout the same problem occurred. I added this following line on recyclerview and the problem no longer persists.

    app:layout_behavior="@string/appbar_scrolling_view_behavior"

Missing this above line will make this problem.

You need to add this attribute to your RecyclerView:

    app:layout_behavior="@string/appbar_scrolling_view_behavior"

i.e.:

<android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!