为什么要使用CardView而不是RelativeLayout或LinearLayout? [英] Why use a CardView instead of a RelativeLayout or LinearLayout?

查看:71
本文介绍了为什么要使用CardView而不是RelativeLayout或LinearLayout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个RecyclerView用于显示项目列表.android给出了这个android CardView类来显示卡的布局.如果我使用RelativeLayout并将其背景设置为白色,则其工作方式相同.同样在CardView的情况下,无论如何我都必须向其添加一个子布局,它基本上包含了卡内的所有视图.因此,我想知道使用CardView(实际上会增加视图的层次结构)而不是直接使用常规Layout是否有任何好处.

I have a RecyclerView for displaying a list of items. There is this android CardView class given by android to show card layout. If I use a RelativeLayout and set its background to white it works the same way. Also in case of CardView I have to anyway add a childlayout to it which basically contains the all the views inside the card. So I wanted to know if their is any benefit of using a CardView (which actually increases the hierarchy of the views) rather than a normal Layout directly.

推荐答案

卡片相对于布局有一些优势,包括:

There are some advantages of cards over layouts, including:

  • 圆角,高程等-只需使用卡片就可以即开即用"的视觉效果
  • 它们支持各种长度的内容.实际上,布局也支持这种布局,但是在列表/网格视图的上下文中,布局的意图是具有相同的大小,而卡片的长度可能会有所不同(例如,当您显示评论或描述时)
  • 相同层次结构级别的卡片可以具有不同类型的内容/视图,与布局(列表/网格项)不同,布局(列表/网格项)在显示集合时应该具有相似的布局

所有这些功能和其他功能都可以在卡的设计指南中找到.

All these and other features can be found in the card's design guideline.

简而言之:

  • 当我要显示一组可能因其内容(例如带有说明和注释的图片)或大量补充操作而具有不同长度/高度的项目时,我会使用卡片.
  • 当我想显示一个简单的项目集合时,我将使用相对/线性布局,所有/大多数项目具有相同的布局,并且文本,图标和操作的数量有限(最多1,2行),ETC.所有项目都相同的元素

这篇关于为什么要使用CardView而不是RelativeLayout或LinearLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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