可以将 cardview 用于列表视图项以及如何使用 [英] Can one use cardview for listview item and how
问题描述
我想在我的应用程序中实现 CardView
,以便所有 ListView
项目都是 CardView
.是不是像在CardView
中封装一个ListView
项XML那么简单?
是的.在 CardView
下面只是一个简单的 FrameLayout
,你可以将它膨胀成一个 ListView
(或 RecyclerView
).>
这是一个例子:
<线性布局android:layout_width="fill_parent"android:layout_height="wrap_content"机器人:方向=垂直"><图像视图android:id="@+id/iv_cover"android:layout_width="wrap_content"android:layout_height="160dp"android:scaleType="centerCrop"android:src="@drawable/placeholder"/>...</LinearLayout></android.support.v7.widget.CardView>
下面是实际操作中的示例:
当然,您需要实现自定义适配器将它们连接在一起.但这实际上与任何自定义 ListView
项目一样.没什么特别的.
I would like to implement CardView
in my app so that all ListView
items are CardView
s. Is it as simple as encapsulating a ListView
item XML in CardView
?
Yes. Underneath CardView
is just a simple FrameLayout
that you could just inflate into a ListView
(or RecyclerView
).
Here's an example:
<android.support.v7.widget.CardView
android:id="@+id/ly_root"
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"
android:background="#FEFEFE"
android:layout_margin="8dp"
app:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_cover"
android:layout_width="wrap_content"
android:layout_height="160dp"
android:scaleType="centerCrop"
android:src="@drawable/placeholder"/>
...
</LinearLayout>
</android.support.v7.widget.CardView>
And here's that example live in action:
Of course you would need to implement a custom adapter to wire them up together. But this is as with any custom ListView
item really. There's nothing special about it.
这篇关于可以将 cardview 用于列表视图项以及如何使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!