Home > Software design >  RecyclerView last row cut off on the bottom
RecyclerView last row cut off on the bottom

Time:04-22

For some reason the last row of my recycler view is cut off like this and I can't scroll down further.

RecyclerView picture

I have a custom adapter for it. If I make the row height more smaller I can make the bottom appear but I want the row to be that height. Is there a way to make the recycler view scroll further down so the last row appears?

layout xml for my custom adapter:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical" android:layout_width="match_parent"
    android:layout_height = "wrap_content"
    android:id="@ id/mainLayout">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding = "12dp">

            <TextView
                android:id="@ id/textViewID"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="1"
                android:textColor="@color/black"
                android:textSize="20sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@ id/textViewSubject"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:text="TextView"
                android:textColor="#000000"
                android:textSize="24sp"
                app:layout_constraintStart_toEndOf="@ id/textViewID"
                app:layout_constraintTop_toTopOf="@ id/textViewID" />

            <TextView
                android:id="@ id/textViewLastmodified"
                android:layout_width="182dp"
                android:layout_height="23dp"
                android:layout_marginTop="8dp"
                android:text="Last Modified: "
                app:layout_constraintStart_toStartOf="@ id/textViewSubject"
                app:layout_constraintTop_toBottomOf="@ id/textViewSubject" />

            <TextView
                android:id="@ id/textViewDate"
                android:layout_width="81dp"
                android:layout_height="68dp"
                android:layout_marginTop="24dp"
                android:layout_marginEnd="16dp"
                android:text="Created on: "
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.cardview.widget.CardView>

</LinearLayout>

XML layout of the activity with my recyclerview

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="wrap_content"
    tools:context=".ShowActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@ id/recyclerView2"
        android:paddingTop="?attr/actionBarSize"
        android:layout_width="409dp"
        android:layout_height="729dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

CodePudding user response:

To fix the issue you can 1) set root view height to match_parent and 2) replace fixed size of recyclerview to 0dp to fit the screen.

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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" <!-- 1 -->
    tools:context=".ShowActivity">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@ id/recyclerView2"
        android:paddingTop="?attr/actionBarSize"
        android:layout_width="409dp"
        android:layout_height="0dp" <!-- 2 -->
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
  • Related