0

I have fragment with 2 RecyclerView. I get some data from api and add it for RecyclerViews in ArrayLists, then notify view that data was changed. For some reason, the last element(s) of the RecyclerViews is getting cut-off. When i get 8 object - RVs show only 5 of them. On small screens even less. I am disable RVs scrolling, and want use one ScrollView for all fragment content.

This is the XML of the fragment:s

<?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"
    tools:context=".screens.view.MainFragment">

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/onDutyMainRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingHorizontal="@dimen/margin_m"
                android:paddingVertical="@dimen/margin_m">

                <TextView
                    android:id="@+id/requestTitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent"
                    android:fontFamily="@font/sfprotext_semibold"
                    android:textStyle="bold"
                    android:textSize="@dimen/on_duty_main_subtitle_font_size"
                    android:textColor="@color/dark_liver"
                    android:text="Requests"
                    tools:text="Requests"/>

                <Button
                    android:id="@+id/showAllRequestsButton"
                    style="@style/ShowAllButtonDark"
                    app:layout_constraintBottom_toBottomOf="@+id/requestTitle"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="@+id/requestTitle"
                    tools:ignore="TouchTargetSizeCheck"
                    android:text="Show All"
                    tools:text="Show All" />

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/requestsRecyclerView"
                    android:layout_width="match_parent"
                    android:layout_marginTop="@dimen/on_duty_recycler_view_margin_top"
                    android:layout_height="wrap_content"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/requestTitle" />

                <TextView
                    android:id="@+id/groupTitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:fontFamily="@font/sfprotext_semibold"
                    android:textColor="@color/dark_liver"
                    android:textSize="@dimen/on_duty_main_subtitle_font_size"
                    android:textStyle="bold"
                    android:layout_marginTop="@dimen/margin_m"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/requestsRecyclerView"
                    android:text="Groups"
                    tools:text="Groups" />

                <androidx.recyclerview.widget.RecyclerView
                    android:id="@+id/groupsRecyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/on_duty_recycler_view_margin_top"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/groupTitle" />

            </androidx.constraintlayout.widget.ConstraintLayout>
        </ScrollView>

    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

I try found solution in other question like that, but nothing helped me. For examle, i tryed some solution from RecyclerView is cutting off the last item

Sunbey13
  • 339
  • 4
  • 12
  • Try `layout_height = 0dp` for RececlerView – vhmvd Dec 12 '22 at 14:41
  • @Ahmn21 It does not help – Sunbey13 Dec 12 '22 at 14:50
  • 1
    You are having recyclerview inside scroll view that might be the problem. 1. Try to set nestedscrollingEnabled false to recycler view. 2. Try to constraint the bottom recyclerview to the bottom of the parent. 3. try replacing scrollview with nestedScrollView. – Manohar Dec 12 '22 at 15:55
  • It is not recommended to put a `RecyclerView` inside a `ScrollView`. It will defeat the purpose of "Recycle" in the `RecyclerView`. For your issue, try setting `android:layout_height` of `ScrollView` to `math_parent`. – Sovathna Hong Dec 12 '22 at 16:34
  • @Manohar i try your 2 and 3 advices and it helped me. Thanks a lot – Sunbey13 Dec 13 '22 at 07:58

0 Answers0