Adding buttons below recyclerview android

If you have a recyclerview in android, you must have given the width and height equal to "match_parent" as described in the official android tutorial Lists and Cards.

When you give the list height and width equal to that of the screen, then it occupies the whole height, and even if you add any button or view below the recyclerview, it will not be displayed.

You can see the button is not displayed and is below the screen

Button displayed below the screen (not visible)
Button displayed below the screen (not visible)

How to add buttons below the recycler view?

If we can align the button to the bottom of the screen, then it will be shown. But in order to align the button to the bottom of the screen, the parent layout has to be RelativeLayout. So we will use a relative layout, add our reyclerview and button inside it, and make the button align to the bottom of its parent. Then we will give margin bottom to the recyclerview so that the recycler view and the button do not overlap.

So our final view will be

Button now visible
Button now visible

Sample code

<RelativeLayout>
<android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginBottom="100px"
         />

    <Button
        android:layout_width="400px"
        android:layout_height="100px"
        android:layout_alignParentBottom="true"
        android:text="Save" />

</RelativeLayout>