Can't access a recyclerview below a fragment when app is rotated to landscape

I tried adding a scrollView/nestedScrollView around the fragment and a few other views (I don’t want the toolbar to scroll). The problem is if I wrap the scrollView around the recyclerview I lose the functionality of the recyclerview. I would like to be able to scroll just far enough down the screen so the recyclerview is visible and be able to scroll through the recyclerview to access its items separately.

The issue specifically happens when I rotate the screen to landscape. In portrait only the recyclerview should scroll. But when we’re in landscape, the fragment takes up the entire screen and I can’t access the recyclerview without some sort of scroll. If I just put the scroll around the fragment then I can’t get far enough down the screen to access the recyclerview.

Is there any way to achieve this?

Here’s a screen grab of how my view looks in portrait. enter image description here

Here’s the XML for the above view (note: this has the recyclerview within the nestedScrollView so most of the screen scrolls at the moment and I loose individual functionality for the recyclerview).

   <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:id="@+id/root_container"     android:fitsSystemWindows="true"     tools:context="com.vuedeu.activities.MainActivity"     android:background="@android:color/black">      <include layout="@layout/generic_toolbar"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:id="@+id/toolbar_container"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintTop_toTopOf="parent"/>      <androidx.core.widget.NestedScrollView         android:layout_width="0dp"         android:layout_height="0dp"         app:layout_constraintStart_toStartOf="parent"         app:layout_constraintEnd_toEndOf="parent"         app:layout_constraintTop_toBottomOf="@id/toolbar_container"         app:layout_constraintBottom_toBottomOf="parent">          <androidx.constraintlayout.widget.ConstraintLayout             android:id="@+id/content_container"             android:layout_width="match_parent"             android:layout_height="wrap_content">              <fragment                 android:name="com.vuedeu.fragments.Fragment"                 android:id="@+id/fragment"                 android:layout_width="0dp"                 android:layout_height="wrap_content"                 app:layout_constraintStart_toStartOf="parent"                 app:layout_constraintEnd_toEndOf="parent"                 app:layout_constraintTop_toTopOf="parent"/>              <View                 android:layout_width="match_parent"                 android:layout_height="2.5dp"                 android:id="@+id/drop_shadow"                 android:background="@drawable/toolbar_dropshadow"                 app:layout_constraintStart_toStartOf="parent"                 app:layout_constraintEnd_toEndOf="parent"                 app:layout_constraintTop_toBottomOf="@id/fragment"/>              <TextView                 android:id="@+id/header_label"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:textSize="18sp"                 android:textColor="@color/toggleTrackActive"                 android:background="@android:color/holo_blue_dark"                 android:padding="15dp"                 tools:text="List Header"                 app:layout_constraintStart_toStartOf="parent"                 app:layout_constraintEnd_toEndOf="parent"                 app:layout_constraintTop_toBottomOf="@id/fragment"/>              <Space                 android:id="@+id/space"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 app:layout_constraintBottom_toBottomOf="@+id/header_label"                 app:layout_constraintEnd_toEndOf="@+id/header_label"                 app:layout_constraintHorizontal_bias="1"                 app:layout_constraintStart_toStartOf="@+id/header_label"                 app:layout_constraintTop_toTopOf="@+id/header_label"                 app:layout_constraintVertical_bias="0"/>              <com.google.android.material.floatingactionbutton.FloatingActionButton                 android:id="@+id/fab_button"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_margin="@dimen/fab_margin"                 app:elevation="6dp"                 android:tint="@color/FABIcon"                 app:backgroundTint="@color/FABIconBg"                 app:pressedTranslationZ="0dp"                 app:borderWidth="0dp"                 app:useCompatPadding="true"                 app:srcCompat="@drawable/ic_event_add_black_24px"                 app:layout_constraintEnd_toEndOf="@+id/space"                 app:layout_constraintTop_toBottomOf="@id/space"/>              <androidx.recyclerview.widget.RecyclerView                 android:id="@+id/recycler_view"                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:divider="@color/drawerBg"                 android:dividerHeight="0dp"                 app:layout_constraintStart_toStartOf="parent"                 app:layout_constraintEnd_toEndOf="parent"                 app:layout_constraintTop_toBottomOf="@id/fab_button"/>          </androidx.constraintlayout.widget.ConstraintLayout>      </androidx.core.widget.NestedScrollView>  </androidx.constraintlayout.widget.ConstraintLayout> 

Any help would be greatly appreciated.

Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.