Android RecyclerView and ListView – Parent view not scrolling enough, ListView hidden-ThrowExceptions

Exception or error:

I have an app where I have a RecyclerView and a ListView in the same layout. The components work well individually. The RecyclerView and ListViews are completely visible and scrollable. However, when I put them on one layout parent as such:

<?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"
    android:paddingLeft="30dp"
    android:paddingRight="30dp"
    android:paddingBottom="30dp"
    android:background="@color/Cerulean">


    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline15"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.02" />

    <androidx.constraintlayout.widget.Guideline
        android:id="@+id/guideline17"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintGuide_percent="0.12" />

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

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

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:divider="@color/Cerulean"
        android:dividerHeight="5dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/guideline17" />

    <ListView
        android:id="@+id/listView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:divider="@color/Cerulean"
        android:dividerHeight="5dp"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/recyclerView" />

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:scaleType="fitCenter"
        android:src="@drawable/logo"
        app:layout_constraintBottom_toTopOf="@+id/guideline17"
        app:layout_constraintEnd_toStartOf="@+id/guideline14"
        app:layout_constraintStart_toStartOf="@+id/guideline13"
        app:layout_constraintTop_toTopOf="@+id/guideline15" />

</androidx.constraintlayout.widget.ConstraintLayout>

I just have a bunch of guidelines to help me place the logo, and I have my recyclerView and listViews after.

I used to just have the ListView, and I was able to scroll through everything. I then added my RecyclerView, which also worked well.

However, when the RecyclerView inflates and shows all its content, I am unable the scroll to my ListView anymore. I can see all the items in my RecyclerView, but as soon as I scroll through my RecyclerView, I hit the “bottom” of my activity, and I am no longer able to see my ListView.

I have also tried to add a ScrollView with nestedScrollingEnabled set to true, but that didn’t help. I could only view my RecyclerView and the top row of my ListView, not to mention that the scroll experience became laggy and subpar.

What do I do in order to guarantee that I can scroll through both my RecyclerView and ListView?

How to solve:

It’s not possible to “concatenate” the items in a RecyclerView and a ListView (that is, once you scroll through the one, it scrolls into the other) by putting one after the other. You should combine both into a single RecyclerView that contains all of the items.

Attempting to get the parent to scroll one into the other is only ever going to result in strange scrolling behavior (as you noted in your comments on the other answer).

###

Try this out :

    <ScrollView 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="fill_parent"
 android:layout_height="wrap_content"
 android:fillViewport="true">

android.support.constraint.ConstraintLayout
android:id="@+id/task_list"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.RecyclerView
    android:id="@+id/first_list_view"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toTopOf="@+id/second_list_view"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_chainStyle="packed" />

<ListView
    android:id="@+id/second_list_view"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/first_list_view" />

Leave a Reply

Your email address will not be published. Required fields are marked *