可以将 cardview 用于列表视图项以及如何使用 [英] Can one use cardview for listview item and how

查看:37
本文介绍了可以将 cardview 用于列表视图项以及如何使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程序中实现 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 CardViews. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆