0

For those who believe this is a duplicate question I have already consulted the current solutions available on stack overflow Such as:

Last Item in recyclerview is cut off RecyclerView cutting off last item

However, no matter what I try I am unable to completely see, on in some cases see at all the last element. I have already checked my adapter to make sure the last item is being rendered. Here are the screenshots and xml. Thanks

    // This is the card view that I render using the adapter
    <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:background="@drawable/card_border_background">

    <ImageView
            android:layout_width="100dp"
            android:layout_height="90dp"
            tools:srcCompat="@tools:sample/avatars"
            android:id="@+id/collectionImage"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
    />
    <TextView
            android:text="collectionName"
            android:layout_width="142dp"
            android:layout_height="49dp"
            android:id="@+id/collectionName"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toEndOf="@+id/collectionImage"
    />
    <TextView
            android:text="productName"
            android:layout_width="141dp"
            android:layout_height="35dp"
            android:id="@+id/productName"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toEndOf="@+id/collectionImage" android:layout_marginTop="56dp"
    />
    <TextView
            android:layout_width="107dp"
            android:layout_height="25dp"
            android:id="@+id/productName2"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintStart_toEndOf="@+id/productName"
            android:text="# available :"
    />
    <TextView
            android:layout_width="32dp"
            android:layout_height="24dp"
            android:id="@+id/numberOfInventoryItems"
            android:text="123"
            app:layout_constraintTop_toBottomOf="@+id/productName2" app:layout_constraintEnd_toEndOf="parent"
            android:layout_marginEnd="16dp"/>
</android.support.constraint.ConstraintLayout>

This is the main layout that contains the recylerview that is inside a nested scrollview. Like I said I tried this solution by reading other threads.

  <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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:id="@+id/main_constraint"
        tools:context=".CollectionDetailsPage">
    <android.support.constraint.ConstraintLayout
            android:id="@+id/top_card"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            app:layout_constraintStart_toStartOf="parent"
            android:background="@drawable/card_border_background"
            android:layout_marginTop="8dp"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            app:layout_constraintTop_toTopOf="parent">

        <ImageView
                android:id="@+id/collection_image_card"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                tools:srcCompat="@tools:sample/avatars"
                app:layout_constraintStart_toStartOf="parent"
                android:layout_marginStart="2dp"
                android:layout_marginTop="2dp"
                app:layout_constraintTop_toTopOf="parent"
                tools:ignore="ContentDescription"/>

        <TextView
                android:id="@+id/collection_title_card"
                android:text="Collection Title"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                app:layout_constraintStart_toEndOf="@+id/collection_image_card"
                app:layout_constraintTop_toTopOf="parent"
                android:layout_marginStart="8dp"
                android:textStyle="bold" android:textSize="18sp" android:textColor="@android:color/black"
                tools:ignore="HardcodedText"/>

        <TextView
                android:id="@+id/collection_html_card"
                android:text="sample body html"
                android:layout_width="200dp"
                android:layout_height="wrap_content"
                app:layout_constraintStart_toEndOf="@+id/collection_image_card"
                android:layout_marginStart="8dp"
                android:layout_marginTop="12dp"
                app:layout_constraintTop_toBottomOf="@+id/collection_title_card"
                tools:ignore="HardcodedText"/>

    </android.support.constraint.ConstraintLayout>

    <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true"
            app:layout_constraintTop_toBottomOf="@+id/top_card"
            android:id="@+id/nestedScrollView"
            android:scrollbars="vertical" app:layout_constraintStart_toStartOf="parent"
           >
        <android.support.v7.widget.RecyclerView
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/recyclerView_Collections_Data"
                tools:ignore="MissingConstraints"/>
    </android.support.v4.widget.NestedScrollView>

    <TextView
            android:text="Loading..."
            android:layout_width="125dp"
            android:layout_height="40dp"
            android:id="@+id/loading_title"
            android:textStyle="bold"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="24sp"
            android:layout_marginStart="16dp"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginTop="12dp"
            app:layout_constraintTop_toBottomOf="@+id/top_card"
            tools:ignore="HardcodedText"/>
    <View
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:background="@color/colorPrimary"
            android:id="@+id/view"
            tools:ignore="MissingConstraints"
            app:layout_constraintBottom_toBottomOf="parent"/>

</android.support.constraint.ConstraintLayout>

enter image description here

Sunil Sunny
  • 3,949
  • 4
  • 23
  • 53
Naman Jain
  • 321
  • 5
  • 21
  • This looks to me to be due to your overall layout rather than the recycler view itself. I recommend looking at using a single constraint layout and checking your positioning. This looks like the recyclerview is sized too large and is flowing off the page. Check out https://stackoverflow.com/questions/53299024/how-to-set-a-views-height-match-parent-in-constraintlayout for some idea of how that should be done. – Ben Neill Jan 18 '19 at 01:38

1 Answers1

2

this obviously is because of:

<View
    android:layout_width="match_parent"

    android:layout_height="25dp"

    android:background="@color/colorPrimary"
    android:id="@+id/view"
    tools:ignore="MissingConstraints"
    app:layout_constraintBottom_toBottomOf="parent"/>

have you ever had a closer look at the first one CardView ??

android:fillViewport="true" and tools:ignore="MissingConstraints" look suspicious;

replace these ConstraintLayout with LinearLayoutCompat, because these are linear layouts.

that NestedScrollView just would need weight 1.00 and height 0dp, to fill the space.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Linear Layout is correct answer. Everything else was fine. Why though? Constraint layout is much better than linear layout. I dont know why it wont work. – Naman Jain Jan 18 '19 at 23:53
  • @NamanJain why should a `ConstraintLayout` be better (or suit better), when the layouts are obviously one horizontal and one vertical linear layout? `ConstraintLayout` should only be used, when items need to be aligned in relation to each other; for example, when irregular floating is required, which a linear layout cannot provide. – Martin Zeitler Jan 18 '19 at 23:58