androidandroid-recyclerviewandroid-relativelayout

RelativeLayout problem: how to set RecyclerView not to overlap a Button on bottom


This is my activity: SearchView on top, RecyclerView on middle, and a Button at bottom

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="@drawable/app_background"
    tools:context=".ui.home.customer.CustomerListActivity">

    <androidx.appcompat.widget.SearchView
        android:background="@color/white"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/searchCustomer" />

    <androidx.recyclerview.widget.RecyclerView
        android:layout_marginLeft="20dp"
        android:clipToPadding="false"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/searchCustomer"
        tools:listitem="@layout/row_item_customer"
        android:id="@+id/rvCustomers" />

    <com.google.android.material.button.MaterialButton
        android:id="@+id/btnAddCustomer"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="20dp"
        android:textColor="@color/text_blue_1"
        app:backgroundTint="@color/white"
        android:layout_width="match_parent"
        android:layout_height="53dp"
        android:text="Add Customer" />

</RelativeLayout>

enter image description here

Turns out it doesn't work as I expected, because the RecyclerView overlaps/crosses the Button. I want the RecyclerView to "stay" on top of the Botton. How to fix this?


Solution

  • Just add following line in recyclerView

    android:layout_above="@id/btnAddCustomer"