Karu
Karu

Reputation: 1005

Recyclerview items overflow from the bottom of the screen in android

I have a xml layout that has a combination of image view, constraint layout and a recycler view. When I scroll the recycler view items, a few of the last items cannot be scrolled to the top fully. These items go beyond the bottom constraint. I have noticed one thing that if my layout consists of only recycler view then this is not a problem. Could this be an issue because my xml layout has an image view, constraint layout as well as a recycler view?

Following is my xml layout, events_fragment.xml

<?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"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    xmlns:tools="http://schemas.android.com/tools">

    <ImageView
        android:id="@+id/itemThumbnail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:paddingBottom="16dp"
        android:visibility="gone"
        android:src="@drawable/social_facebook_teal"
        app:layout_constraintDimensionRatio="3:2"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/errorMessage"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:paddingLeft="16dp"
        android:paddingTop="16dp"
        android:paddingRight="16dp"
        android:visibility="gone"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/itemThumbnail" />

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/headerCL"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginStart="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        android:visibility="gone"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/itemThumbnail">

        <TextView
            android:id="@+id/dateHeader"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Date"
            android:textSize="18sp"
            android:textStyle="bold"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintRight_toLeftOf="@+id/guidelineNavHeight1">
        </TextView>

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guidelineNavHeight1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.25" />

        <TextView
            android:id="@+id/eventHeader"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Event"
            android:textSize="18sp"
            android:textStyle="bold"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toRightOf="@+id/guidelineNavHeight1"
            app:layout_constraintRight_toLeftOf="@+id/guidelineNavHeight2">
        </TextView>

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guidelineNavHeight2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.70" />
        <TextView
            android:id="@+id/timeHeader"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="Time"
            android:textSize="18sp"
            android:textStyle="bold"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toRightOf="@+id/guidelineNavHeight2"
            app:layout_constraintRight_toLeftOf="@+id/zoneHeader">
        </TextView>
        <TextView
            android:id="@+id/zoneHeader"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="(CST/CDT)"
            android:textSize="12sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintLeft_toRightOf="@+id/timeHeader"
            app:layout_constraintRight_toRightOf="parent">
        </TextView>
    </androidx.constraintlayout.widget.ConstraintLayout>

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swipeRefresh"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/headerCL">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/eventsRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

Below is my item layout, event_item.xml

<?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"
    android:layout_marginStart="16dp"
    android:layout_marginTop="8dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="16dp">

    <TextView
        android:id="@+id/date"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text=""
        android:textSize="12sp"
        android:textStyle="bold"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintRight_toLeftOf="@+id/guidelineNavHeight1">
    </TextView>

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guidelineNavHeight1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.25" />

    <TextView
        android:id="@+id/event"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text=""
        android:textSize="12sp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/guidelineNavHeight1"
        app:layout_constraintRight_toLeftOf="@+id/timeHeader">
    </TextView>

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guidelineNavHeight2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_percent="0.70" />
    <TextView
        android:id="@+id/time"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text=""
        android:textSize="12sp"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/guidelineNavHeight2"
        app:layout_constraintRight_toRightOf="parent">
    </TextView>
</androidx.constraintlayout.widget.ConstraintLayout>

Upvotes: 0

Views: 666

Answers (1)

Bryan.C
Bryan.C

Reputation: 53

I think your events fragrment constraint layout height should be match_parent

Upvotes: 2

Related Questions