繁体   English   中英

RecyclerView最后一个元素不显示或被切断

[英]RecyclerView Last Element Not Showing or getting cut off

对于那些认为这是重复问题的人,我已经咨询了堆栈溢出时可用的当前解决方案,例如:

recyclerview中的最后一个项目被切除 RecyclerView中切除的最后一个项目

但是,无论我尝试什么,都无法完全看到,在某些情况下,甚至看不到最后一个元素。 我已经检查了我的适配器,以确保最后一个项目被渲染。 这是屏幕截图和xml。 谢谢

    // 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>

这是主布局,其中包含位于嵌套滚动视图内部的recylerview。 就像我说过的,我通过阅读其他线程尝试了此解决方案。

  <?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>

在此处输入图片说明

这显然是因为:

<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"/>

您是否曾经仔细查看过第一个CardView

android:fillViewport="true"tools:ignore="MissingConstraints"看起来可疑;

LinearLayoutCompat替换这些ConstraintLayout ,因为它们是线性布局。

NestedScrollView仅需要权重1.00和高度0dp来填充空间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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