62

I have a fragment with a toolbar and a recyclerView inside it.

I am populating the recyclerView with dummy data and then try to show them. For some reason, the last element of the recyclerView is getting cut-off.

This is the XML of the fragment:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_1"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar_layout"
        android:layout_width="match_parent"
        android:layout_height="@dimen/height_of_app_bar"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/primary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/placeholder_rect_header"
                app:layout_collapseMode="parallax"/>

            <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/ThemeOverlay.AppCompat.Light"/>

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

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

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

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

The items at the list are really simple ones:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:background="@color/background_1"
    android:orientation="horizontal"
    android:padding="@dimen/space_for_a_bit_of_air">

    <ImageView
        android:id="@+id/album_cover"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_gravity="center_vertical"
        android:scaleType="fitXY"
        android:src="@drawable/placeholder_album_cover"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_marginLeft="@dimen/space_for_distinguishing_stuff"
        android:orientation="vertical">

        <TextView
            android:id="@+id/album_title"
            style="@style/titleText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/sample_text_c"/>

        <TextView
            android:id="@+id/album_year"
            style="@style/subtitleText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/sample_text_a"/>

    </LinearLayout>

</LinearLayout>

I am now at the end of the list, but the last element still looks cut-off

I am now at the end of the list, but the last element still looks cut-off.

I am using the latest version as of 2015-09-23 of google libraries, 23.0.1, (i.e. com.android.support:recyclerview-v7:23.0.1), and the following configuration at the build.gradle:

compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
   minSdkVersion 14
   targetSdkVersion 23
   versionCode 1
   versionName "1.0"

   multiDexEnabled true// Enabling multidex support
 }

Any help would be greatly appreciated since I am going nuts with this problem :(

SOLUTION

Ok, after cleaning the code to the bare essentials and removing complexity, I found the problem: it was a combination of wrong flags and missing or extra attributes. The following works fine for both Android 4.x and 5.x:

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_1"
    android:fitsSystemWindows="true">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:collapsedTitleTextAppearance="@style/Title.collapsed"
            app:contentScrim="@color/primary"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleTextAppearance="@style/Title.Expanded"
            app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed">

            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/artistic_4"
                app:layout_collapseMode="parallax"/>

            <View
                android:layout_width="match_parent"
                android:layout_height="@dimen/height_of_app_bar"
                android:background="@drawable/gradient"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"/>

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

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

    <android.support.v7.widget.RecyclerView
        android:id="@+id/simpleList"
        style="@style/genericRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:listitem="@layout/item_discography_album"/>

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

In a nutshell, android:fitsSystemWindows="true" should only be at the coordinatorLayout, AppBarLayout and theCollapsingToolbarLayout (which are the ones that we want to be adjusted based on the screen on Android 5.x), the app:layout_scrollFlags should be set to "scroll|enterAlways|enterAlwaysCollapsed" and the toolbar should have as height, the height of the actionBar. Finally, it's better to keep the RecyclerView as clean as possible so you can control the layout spacing at each line item.

Sotiris Falieris
  • 911
  • 1
  • 10
  • 18
  • Mine is a simple constraint layout with just a toolbar and a recyclerview. Your solution may not suit in my case. But @Rami solution sounds generic for the reported issue as the height of the appbar layout needed to be adjusted as bottom margin to fix the problem. – PravyNandas Oct 12 '18 at 10:56
  • This is a weird problem. It only happens on some of my devices. API 27 Pixel 2, but my real device has no problem running Android 11 – DIRTY DAVE Dec 20 '22 at 13:41

31 Answers31

37

Try to change your RecyclerView height to "wrap_content" and add the AppBarLayout height as margin bottom.

<android.support.v7.widget.RecyclerView
        android:id="@+id/simpleList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/height_of_app_bar"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

The cut-off part of the list item, is the height of the AppBarLayout.

Rami
  • 7,879
  • 12
  • 36
  • 66
35

I tried all the available option from most of possible site but I didn't get the solution. Then, I think can I use bottom padding? And Yes, It's work for me.

I am sharing the code to you. Nothing more attribute required other than height, width & padding.

android:paddingBottom="?attr/actionBarSize"

 <android.support.v7.widget.RecyclerView
    android:id="@+id/your id name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingBottom="?attr/actionBarSize"
    app:layout_constraintTop_toBottomOf="@+id/your field" />
Yuvi
  • 639
  • 6
  • 9
26

If you are using Constraint Layout, make sure the layout_height is 0dp and layout_constraintBottom_toBottomOf constraint is set properly.

  <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/titleTextView"
     />
Saurabh Padwekar
  • 3,888
  • 1
  • 31
  • 37
  • This doesn't work for me. API 27. I have also tried placing it inside a constraint layout with 0dp. and ```app:layout_constraintBottom_toBottomOf="parent"``` ```app:layout_constraintTop_toTopOf="parent"``` but doesn't work either – DIRTY DAVE Dec 20 '22 at 13:44
12

This worked for me. Set both height and width of the recyclerView to 0dp

 <android.support.v7.widget.RecyclerView
    android:id="@+id/rv_materias"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginTop="20dp"
    android:background="@color/secondaryLightColor"
    app:layout_constraintBottom_toTopOf="@id/bottom_navigation"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/guideline6"></android.support.v7.widget.RecyclerView>
Sila Siebert
  • 422
  • 4
  • 10
10

You may try following as this is working as expected:

<android.support.v7.widget.RecyclerView
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/layout_header">
</android.support.v7.widget.RecyclerView>
Harish Godara
  • 2,388
  • 1
  • 14
  • 28
5

Use RelativeLayout as a parent of RecycerView.It's working for me.

jyothish
  • 117
  • 1
  • 10
  • 1
    yes, it worked for my scenario, where I was populating data in grid using with nested Recyler views and with the LL being parent made my last view cut and scrollable within its boundaries instead making LL scrollable. Having RL as parent did the trick and whole layout is now scrollable as I wanted. – VipiN Negi May 03 '19 at 08:06
4

For Constraint Layout you can use set the layout_height as 0dp. It will occupy the space left on screen with the Recycler View.

  <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/titleTextView"
     />
Kourosh
  • 2,239
  • 13
  • 18
3

Set layout_height="match_parent" then add layout_marginBottom="?attr/actionBarSize" or 50dp this will compensate for the ToolBar forcing the RecyclerView down cutting off the last view.

Additionally set nestedScrollingEnabled="false" if you have a hideOnScroll enabled toolbar.

<androidx.recyclerview.widget.RecyclerView
     android:id="@+id/my_recycler_view"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_marginBottom="?attr/actionBarSize"
     android:nestedScrollingEnabled="false"  />
Mitch
  • 576
  • 5
  • 11
3

I was facing the same issue and what I did is created a LinearLayout and placed my RecyclerView inside it and it solved my issue. I hope this will solve other issue as well.

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/companyLabelView">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/companiesRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/_8dp"
        android:layout_marginStart="@dimen/_8sdp"
        android:layout_marginLeft="@dimen/_8sdp"
        android:layout_marginTop="@dimen/_8sdp"
        android:layout_marginEnd="@dimen/_8sdp"
        android:layout_marginRight="@dimen/_8sdp"
        android:layout_marginBottom="@dimen/_8sdp"
        android:overScrollMode="never"
        app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:spanCount="3"
        tools:itemCount="10"
        tools:listitem="@layout/company_item_view" />

</LinearLayout>
fdermishin
  • 3,519
  • 3
  • 24
  • 45
Atif AbbAsi
  • 5,633
  • 7
  • 26
  • 47
3

android:paddingBottom ="112dp"

height of the area which is not not visible <112dp in my case>

add this above in your recyclerview

<androidx.recyclerview.widget.RecyclerView
    android:id="@+id/main_recycler"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    android:paddingBottom="112dp"
    app:layout_constraintTop_toBottomOf="@+id/simpleSearchView" />
2

I have a dialog fragment which contains the RecyclerView. For my initial overall constraint layout none of the above solutions worked, so I changed it to a linear layout, which works without problems. This layout contains a toolbar and the recyclerview.

Greg Holst
  • 874
  • 10
  • 23
2

android:paddingBottom ="112dp"

height of the area which is not not visible <112dp in my case>

1

Create a FrameLayout put the RecycerView in it having it match_parent for both the width and the height. You can size the framelayout however you want.

Android
  • 1,420
  • 4
  • 13
  • 23
vanJoseph
  • 11
  • 3
1

I had the same problem (even missing an entire ViewHolder element from my list) while using a RecyclerView inside a ConstraintLayout. As Sila Siebert mentioned, setting layout_width and layout_height of the RecyclerView to zero did the trick. It's a bit confusing cause the editor jumps back to say "match_constraints" after a bit while the XML-text says 0dp. Don't let it confuse you, it should work.

Pauliman
  • 59
  • 5
1

You are missing the bottom constraint. You should add: app:layout_constraintBottom_toBottomOf="parent" on the recylerview.

Ivan Aracki
  • 4,861
  • 11
  • 59
  • 73
lollipop k
  • 37
  • 2
0

Make sure you have layout_height as wrap_content for both RelativeLayout and RecyclerView

Android
  • 1,420
  • 4
  • 13
  • 23
0

I was having the same problem, After searching lot i found out that My parent view holding the recycleView was not properly constrained as i was using constraintLayout,

my view hierarchy was like

constraintLayout->pageViewer with tab->fragment->recyclerView

In my case pageViewer was not constrained properly

to solve this please check weather the parent is properly aliened or constrained

Vaibhav Jadhav
  • 2,020
  • 1
  • 7
  • 20
Asgar Ahmed
  • 47
  • 2
  • 5
0

I know I am late, but today I faced the same issue. I have a ConstrantLayout, a toolbar, a recyclerview. So I used android:layout_height="match_parent", and to prevent the recyclerview from overlapping with the topbar, I used, app:layout_constraintTop_toBottomOf="@id/toolbar" android:layout_marginTop="?attr/actionBarSize"

So the entire code looks something like this:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:onClick="onClick"
    android:background="@color/shop_main_fragment_background"
    >
    <include layout="@layout/toolbar"/>
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rootRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layout_constraintTop_toBottomOf="@id/toolbar"
        android:layout_marginTop="?attr/actionBarSize"
        >
    </androidx.recyclerview.widget.RecyclerView>

</androidx.constraintlayout.widget.ConstraintLayout>

I hope this is helpful.

Qazi Fahim Farhan
  • 2,066
  • 1
  • 14
  • 26
0

I was facing the same issue and nether of the answers were helpful.

I solved this by adding the android:minHeight="?actionBarSize" to CollapsingToolbarLayout.

Maybe this will help someone.

Jeevuz
  • 13
  • 1
  • 8
0

I had similar problem. Adding android:minHeight="?attr/actionBarSize" to CollapsingToolbarLayout helped.

Nguyen Quoc Dat
  • 201
  • 3
  • 7
0

The issue is the bottom of the Recycle View is not properly constrained to the bottom anchor of the parent view. to fix this, within the Recycle View the set the layout_constraintBottom_toBottomOf equal to parent, this will constrain the bottom of the recycle view to be the bottom of the parent view so the view doesn't look cut off.

app:layout_constraintBottom_toBottomOf="parent"
Hermes
  • 2,828
  • 2
  • 14
  • 34
somia molaei
  • 111
  • 1
  • When answering a question, its helpful to include a short explanation of what your answer does to solve the problem. – Hermes Jan 15 '21 at 00:21
0

Set the width and height to match_parent and add a margin at bottom with the value of the bar at top. This saved me from hours of hard work.

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

In this case, I added a constraint on the recyclerView so that it does not overlap outside the screen

app:layout_constraintBottom_toBottomOf="parent"
Izhan Ali
  • 567
  • 7
  • 17
jeremex
  • 66
  • 4
0

Changing constraint layout (parent layout) to linear layout resolved the issue for me.

Sriraksha
  • 459
  • 1
  • 8
  • 15
0

It's very late for party but use, 0dp for height of recyclerView. This will set view with constraint.

android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
Navinpd
  • 772
  • 7
  • 15
0

Use layout_height as 0dp for recycler view and it will solve the issue

0

Adding this to the RecyclerView worked for me (increase the 20dp if needed):

android:layout_marginBottom="20dp"
ZP007
  • 582
  • 7
  • 12
0

I faced this issue while using layout ConstraintLayout so what I did is wrapped my layout inside LinearLayout and Guess what it worked fine I hope this may help you guys. Thanks :)

Atif AbbAsi
  • 5,633
  • 7
  • 26
  • 47
-1
  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="150dp"
  android:layout_marginStart="@dimen/_20"
    android:layout_marginEnd="@dimen/_20"
    app:layout_constraintTop_toBottomOf="@+id/linearLayout">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_Bookingagain"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:focusableInTouchMode="true"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent" />

</RelativeLayout>
  • 2
    provide explanation of how and why this solves the problem would really help to improve the quality of your post. – Android Jun 21 '19 at 10:33
-1
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="8dp"
    >


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="0dp"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:contentInsetStart="0dp"
        android:contentInsetLeft="0dp"
        android:contentInsetEnd="0dp"
        android:contentInsetRight="0dp"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:contentInsetEnd="0dp"
        app:contentInsetLeft="0dp"
        app:contentInsetRight="0dp"
        app:contentInsetStart="0dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    <android.support.constraint.ConstraintLayout
        android:id="@+id/main_area"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar">

        <ProgressBar
            android:id="@+id/progressBarGetFromServer"
            style="?android:attr/progressBarStyle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:indeterminateDrawable="@drawable/bg_circular_progress"
            android:visibility="invisible"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"

            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerViewSecondaryGroup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"

            />
    </android.support.constraint.ConstraintLayout>

</android.support.constraint.ConstraintLayout>
Saeid Amini
  • 1,313
  • 5
  • 16
  • 26
somia molaei
  • 111
  • 1
-4

add android:layout_gravity="top" to recyclerview. if this didn't work add android:layout_gravity="fill_verticle"

Android
  • 1,420
  • 4
  • 13
  • 23
Amol Suryawanshi
  • 2,108
  • 21
  • 29