How to stop RecyclerView from overlapping TextView when scrolling Android TV

46 Views Asked by At

I have an Android TV app that has a RecyclerView below a TextView. Everything looks great until I click down to the third item which causes the RecyclerView to cover the TextView.

<?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="match_parent"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:keepScreenOn="true">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipToPadding="false"
        android:clipChildren="false"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent">

        <TextView
            android:id="@+id/dateTV"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="18sp"
            android:layout_marginStart="@dimen/homeHorizontalMargin"
            android:paddingBottom="20dp" />
        
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_below="@id/dateTV"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="20dp"
            android:layout_marginHorizontal="@dimen/epgRVHorizontalMargin"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:descendantFocusability="afterDescendants" />
    </RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

How can I stop the RecyclerView from overlapping the TextView?

1

There are 1 best solutions below

0
Harshali On

Your RecyclerView parent layout has below property

android:clipToPadding="false"
android:clipChildren="false"

So, when you scroll RecyclerView it will overlap with other view in layout.

You can remove it. Why you use this property here is there any specific reason to design other view in screen?
or you have ConstraintLayout as root layout so why you add RelativeLayout again and put RecyclerView inside this layout.

You can design your XML layout like below

<?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="match_parent"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:keepScreenOn="true">

    <TextView
        android:id="@+id/dateTV"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/homeHorizontalMargin"
        android:paddingBottom="20dp"
        android:textSize="18sp"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_below="@id/dateTV"
        android:layout_marginHorizontal="@dimen/epgRVHorizontalMargin"
        android:layout_marginTop="20dp"
        android:descendantFocusability="afterDescendants"
        android:focusable="false"
        android:focusableInTouchMode="false"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@id/dateTV" />

</androidx.constraintlayout.widget.ConstraintLayout>