解决Android中使用RecyclerView滑动时底部item显示不全的问题

感觉这个bug是不是因人而异啊,找了很多文章都没能解决我的问题,包括在RecyclerView上在嵌套上一层RelativeLayout,添加属性android:descendantFocusability=”blocksDescendants”,使用ConstraintLayout布局包裹RecyclerView,再设置layout_height="0dp"和layout_constraintBottom_toBottomOf="parent"(就是指定约束到parent上),还有什么外部嵌套上ScrollView,NestedScrollView(这个我没有尝试),最后自己改了改,竟然给解决了!

首先,跟使用什么布局是没有关系的(也可能仅限于我的代码),因为我有三个和RecyclerView这个布局相关的xml文件,一个是用来放置RecyclerView的,一个是写RecyclerView的xml,还有一个是item布局文件,我看到的其他方法大都是对RecyclerView的xml文件做更改,然后我自己改的时候突然意识到还可以修改一下放置RecyclerView的xml,发现我在这里设置的layout_height是wrap_content,可以看到design里的这一部分高度是超出了整个盒子一部分的,然后我就把layout_height改成0dp,这时design里的高度是是没有变化的,在此基础删设置了对该部分的限制,代码如下,其实主要就是把layout_height改成0dp,然后再加上app:layout_constraintBottom_toBottomOf="parent",就大功告成了!

<androidx.viewpager.widget.ViewPager
        android:id="@+id/fixedViewPager"
        android:layout_width="380dp"
        android:layout_height="0dp"
        app:layout_constraintEnd_toEndOf="@+id/sliding_tab"
        app:layout_constraintStart_toStartOf="@+id/sliding_tab"
        app:layout_constraintTop_toBottomOf="@+id/sliding_tab"
        app:layout_constraintBottom_toBottomOf="parent"/>

写到这里突然想到可能那些文章的方法是可行的,只不过我没改对地方,一直改的是写RecyclerView的xml文件,一直没转过弯来,导致解决这个问题花了两个多小时,记录一下

猜你喜欢

转载自blog.csdn.net/qq_62070939/article/details/128142612