android -------- ConstraintLayout中RecyclerView 数据显示不全

使用ConstraintLayout只要一层就能够实现了。减少了布局层级的嵌套,绘制性能也提高了很多很多

ConstraintLayout 嵌套RecyclerView 导致最后的几条数据显示不全

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorWhite">


    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:focusable="true"
        android:focusableInTouchMode="true"
        app:layout_constraintTop_toTopOf="parent" />


    <VideoView
        android:id="@+id/long_video_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintDimensionRatio="16:10"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ImageView
        android:id="@+id/iv_back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="18dp"
        android:src="@drawable/ic_video_content_back"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/toolbar" />


    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recycler_video_comment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="@dimen/x65"
        android:overScrollMode="never"
        android:scrollbars="none"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/long_video_view"> 
   </androidx.recyclerview.widget.RecyclerView>



   

</androidx.constraintlayout.widget.ConstraintLayout>

如果不设置 app:layout_constraintBottom_toBottomOf="parent",就会导致最后的几条item显示不全。

一定要给recycleview设置约束

这两个属性加上节ok了

android:layout_height="0dp"

app:layout_constraintBottom_toBottomOf="parent"

发布了333 篇原创文章 · 获赞 181 · 访问量 65万+

猜你喜欢

转载自blog.csdn.net/DickyQie/article/details/104973355