4

Here is a screenshot of what is happening:

enter image description here

For some reason, the last card of the RecyclerView is not showing up properly. This is a weird occurrence especially since the RecyclerView is just wrapping content.

<android.support.v7.widget.RecyclerView
    android:id="@+id/cardList"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="3dp"
    android:layout_marginLeft="8dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

Why might something like this occur? How can I make it so that the RecyclerView is not cut off?

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
George Yang
  • 694
  • 6
  • 18
  • 4
    This usually happens with wrap_content. have you tried `match_parent` ? – poss Aug 20 '15 at 17:02
  • Is this a bug with wrap_content? I will try match_parent and see what happens. Thanks for the suggestion. EDIT: Just tried it and it fixed the problem. Thanks poss! – George Yang Aug 20 '15 at 17:03
  • have a look at my answer https://stackoverflow.com/questions/32742724/recyclerview-is-cutting-off-the-last-item/60314197#60314197 – Atif AbbAsi Feb 20 '20 at 06:43

6 Answers6

3

Solved by poss: https://stackoverflow.com/users/4048794/poss

choosing wrap_content as the attribute for layout_width and layout_height causes the cut-off on RecyclerViews

Community
  • 1
  • 1
George Yang
  • 694
  • 6
  • 18
1

RecyclerView cannot have WRAP_CONTENT as layout_height. The solution is to set layout_height to a specific value like "100dp", like the following:

<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="100dp"
    ...
/>

Now if the value in the xml is not what you want, you can set layout_height in the code using requestLayout();

david m lee
  • 2,547
  • 26
  • 14
1

I have a RecyclerView similar to Marcin Orlowski's. Now it works for me after I applied the solution of setting the height of layout_height in Java using requestLayout. It cannot be set in onCreate method, however. It needs to be set in onWindowFocusChanged method.

@Override
public void onWindowFocusChanged (boolean hasFocus) {
    DisplayMetrics dm = new DisplayMetrics();
    this.getWindowManager().getDefaultDisplay().getMetrics(dm);

    int[] loc = new int[2];
    recyclerView.getLocationOnScreen(loc); // get the location of the recyclerview
    int distance_to_bottom = dm.heightPixels - loc[1]; // similar to Marcin's design
    // RecyclerView 直到版面的最下端
    ViewGroup.LayoutParams params = recyclerView.getLayoutParams();
    params.height = distance_to_bottom;
    recyclerView.requestLayout(); // set it right here
}
Liwen Zhao
  • 545
  • 5
  • 9
1

I had the same problem.Then i try to add some space in the bottom of the recyclerview. If you try all the above solutions and still got the issue, then try this one.

add

android:clipToPadding="false"

to your recyclerview code . like this

<RecyclerView
 android:id="@+id/my_rv"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="10dp"
 android:clipToPadding="false" />
san88
  • 1,286
  • 5
  • 35
  • 60
0

Same happened to me, so I just added three main inside my recycler View:

  1. First of all, give your recycler View height and width as: match parent

  2. Secondly give bottom padding, as paddingBottom = "10dp"

  3. Include, clipToPadding = "false"

    <androidx.recyclerview.widget.RecyclerView android:id="@+id/postRV" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="10dp" android:clipToPadding="false" android:layout_marginTop="80dp" app:layout_behavior="@string/appbar_scrolling_view_behavior" />

Momina Javed
  • 81
  • 2
  • 5
0

If you have an header above the RecyclerView, setting

        android:layout_height="match_parent"

is not a good choice, because the RecyclerView will overlap with the header.

This can be solved by setting, as someone already said, layout_height attribute to a fixed value, like

        android:layout_height="300dp"
Lucas
  • 458
  • 4
  • 6