3

My reclerview's last row is being covered by my bottom app bar.

My code is as follows:

activity_home.xml

<?xml version="1.0" encoding="utf-8"?>

<layout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <fragment
                android:id="@id/Container_fromHomeActivity_BottomAppBarFragments"
                android:name="androidx.navigation.fragment.NavHostFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:defaultNavHost="@bool/Navigation_NavigationHost_Default"
                app:navGraph="@navigation/bottomappbar_navigation"/>

            <com.google.android.material.bottomappbar.BottomAppBar
                    android:id="@id/BottomAppBar_fromHomeActivity_Main"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    app:fabAlignmentMode="center"
                    app:navigationIcon="@drawable/ic_menu_dark"
                    app:menu="@menu/menu_bottomappbar_main"/>


            <com.google.android.material.floatingactionbutton.FloatingActionButton
                    android:id="@id/FAB_fromHomeActivity_BottomAppBarAttached"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/ic_add_dark"
                    android:backgroundTint="@color/colorAccent"
                    app:layout_anchor="@id/BottomAppBar_fromHomeActivity_Main"/>

    </androidx.coordinatorlayout.widget.CoordinatorLayout>

</layout>

My reclerview is in a fragment from my home activity:

fragment.xml

<layout
    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">

<androidx.constraintlayout.widget.ConstraintLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/todoList"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="8dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>

</layout>

However, the last row is only half visible as such:

RecyclerView

From the material guidelines, the Bottom App Bar and FAB SHOULD be inside a coordinator layout for them to work together. So how am i supposed to lift my recyclerview above the bottom app bar so that the last row is visible too?

I don't want to add padding or margin at the end because it doesn't seem to be good coding...

Please help!

Mervin Hemaraju
  • 1,921
  • 2
  • 22
  • 71
  • Possible duplicate of [How to add margins to a RecyclerView for the last element?](https://stackoverflow.com/questions/37011982/how-to-add-margins-to-a-recyclerview-for-the-last-element) – Reaz Murshed May 31 '19 at 21:29
  • I don't want to add padding, i want it to be above the bottom app bar so that the last row is visible. – Mervin Hemaraju May 31 '19 at 21:32
  • The idea is to add some bottom margin to the `RecyclerView` so that it stays above the bottom nav bar. – Reaz Murshed May 31 '19 at 21:33

3 Answers3

4

I used android:layout_marginBottom="?attr/actionBarSize" on my RecyclerView and it worked... Thanks

Mervin Hemaraju
  • 1,921
  • 2
  • 22
  • 71
2

Quick fix:

Try with these attributes:

<androidx.constraintlayout.widget.ConstraintLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false">

<androidx.recyclerview.widget.RecyclerView
        android:id="@+id/todoList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="56dp"
        android:clipToPadding="false"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" android:layout_marginTop="8dp"/>

</androidx.constraintlayout.widget.ConstraintLayout>
Nezih Yılmaz
  • 626
  • 4
  • 8
0

Try to add a constraint for the recyclerView to the bottom of the parent app:layout_constraintBottom_toBottomof="parent"