NestedScrollView 加上:
android:fillViewport="true"
如果用约束布局ConstraintLayout,就还是会出现显示不全的问题,只会显示一行。即便是用requestLayout都不行,计算条目高度没试过,没必要那么麻烦。
处理办法是在RecyclerView外边用一个布局包住,我是用的RelativeLayout包住的。
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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:fillViewport="true"
android:paddingTop="@dimen/padding_default"
android:paddingBottom="@dimen/padding_default">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/hot_list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>