RecyclerView
高度使用wrap_content
时最后一行显示不全,需在RecyclerView
包裹一层布局,并确定外层布局的高度;或者分配剩余空间;如果父布局使用ConstraintLayout
,则确定顶部和底部定位,并且高度设为0dp
。如果外层嵌套ScrollView
,改成NestedScrollView
。
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/color_F4F4F4">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tb_toolbar"
app:layout_constraintBottom_toBottomOf="parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_timer_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:background="@drawable/bg_white_corner_8" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>