Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: last card of RecyclerView cut off. Can't scroll any further. Why would this happen?

Tags:

android

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?

like image 913
George Yang Avatar asked Oct 14 '25 20:10

George Yang


2 Answers

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

like image 87
George Yang Avatar answered Oct 17 '25 12:10

George Yang


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();

like image 39
david m lee Avatar answered Oct 17 '25 10:10

david m lee