简体   繁体   中英

RecyclerView Last Element Not Showing or getting cut off

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>

在此处输入图片说明

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM