如何使用androidx.recyclerview.widget.RecyclerView?

问题描述 投票:0回答:1

这是RecyclerView: enter image description here 这是 CardView: enter image description here 但设计选项卡向我展示了这一点: enter image description here 我想尝试这样做: enter image description here 我该如何解决它?

android android-recyclerview preview
1个回答
0
投票

当我检查您的问题图像时,您的 RecyclerView 项目布局已占据每个项目的整个屏幕高度。问题是你将 Cardview 的layout_ height设置为“match_parent”,这就是为什么它需要全高。

这里需要改变的是,

<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"> <!-- here you need to change wrap_content-->

...
...

</androidx.cardview.widget.CardView>
© www.soinside.com 2019 - 2024. All rights reserved.