Solve the problem that the bottom item is not fully displayed when using RecyclerView to slide in Android

I feel that this bug is different from person to person. I found many articles but failed to solve my problem, including nesting a layer of RelativeLayout on RecyclerView, adding the attribute android:descendantFocusability="blocksDescendants", and wrapping RecyclerView with ConstraintLayout layout , and then set layout_height="0dp" and layout_constraintBottom_toBottomOf="parent" (that is, specify the constraint to the parent), and what is the external nested ScrollView, NestedScrollView (I haven't tried this), and finally changed it myself, and it was solved !

First of all, it has nothing to do with what layout is used (it may be limited to my code), because I have three xml files related to the layout of RecyclerView, one is used to place RecyclerView, the other is to write RecyclerView xml, and One is the item layout file. Most of the other methods I saw were to change the xml file of RecyclerView. Then when I changed it myself, I suddenly realized that I could also modify the xml where RecyclerView was placed. I found that the layout_height I set here is wrap_content. It can be seen that the height of this part in the design exceeds the whole part of the box, and then I changed the layout_height to 0dp. At this time, the height in the design does not change. Based on this, the restriction on this part is set. The code is as follows, in fact, the main thing is to change the layout_height to 0dp, and then add app:layout_constraintBottom_toBottomOf="parent", and you're done!

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

When I wrote this, I suddenly thought that the method of those articles might be feasible, but I didn’t change the right place. What I kept changing was to write the xml file of RecyclerView, and I didn’t turn around. It took more than two hours to solve this problem. record it

Guess you like

Origin blog.csdn.net/qq_62070939/article/details/128142612