RecyclerView与CardView的使用(二)

简介: RecyclerView与CardView的使用(二)

3.当RecyclerView遇上CardView


CardView继承自Framelayout,所以FrameLayout所有属性CardView均可以直接拿来用,不过CardView还有自己独有的属性。下面我们将item布局的父标签换成CardView。并且用RelativeLayout包裹两个子控件。代码如下:

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="5dp">
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageView
            android:id="@+id/lyj_image"
            android:layout_width="wrap_content"
            android:layout_centerInParent="true"
            android:layout_marginRight="5dp"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/lyj_txt"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/lyj_image"
            android:layout_marginTop="40dp" />
    </RelativeLayout>
</android.support.v7.widget.CardView>


运行效果图如下:


37.png


其每个item变成了一个卡片的样式,如果色彩搭配的好,那么界面将如上线的APP一样酷炫。


下面来介绍CardView独有的属性:


app:cardElevation 阴影的大小

app:cardMaxElevation 阴影最大高度

app:cardBackgroundColor 卡片的背景色

app:cardCornerRadius 卡片的圆角大小

app:contentPadding 卡片内容于边距的间隔◦card_view:contentPaddingBottom

app:contentPaddingTop

app:contentPaddingLeft

app:contentPaddingRight

app:contentPaddingStart

app:contentPaddingEnd

app:cardUseCompatPadding 设置内边距,V21+的版本和之前的版本仍旧具有一样的计算方式

app:cardPreventConrerOverlap 在V20和之前的版本中添加内边距,这个属性为了防止内容和边角的重叠


下面简单设置几个属性:


app:cardBackgroundColor="#EEC900":卡片背景为黄色。


app:cardCornerRadius="10dp":卡片圆角半径为10dp。


app:cardPreventCornerOverlap="true":防止内容与边角重叠


app:cardUseCompatPadding="true":设置边距


app:contentPadding="10dp":边距的间隔大小为10dp


运行一下效果图如下所示:

38.png


相关文章
|
前端开发 Java Spring
架构设计的分层架构
架构设计的分层架构
|
存储 数据库 数据安全/隐私保护
OBCP第七章 OB迁移-备份恢复技术架构及操作方法
OBCP第七章 OB迁移-备份恢复技术架构及操作方法
363 0
|
API Android开发 容器
33. 【Android教程】悬浮窗:PopupWindow
33. 【Android教程】悬浮窗:PopupWindow
1887 2
|
存储 JSON 前端开发
需要token的原因----
需要token的原因----
409 0
|
C# 数据安全/隐私保护
推荐三款开源且实用的.NET代码混淆工具,保护你的.NET应用程序
推荐三款开源且实用的.NET代码混淆工具,保护你的.NET应用程序
1100 0
|
存储 Linux Shell
Linux内核追踪(一):proc/sys/debugfs
Linux内核追踪(一):proc/sys/debugfs
367 0
|
SQL 关系型数据库 MySQL
MySQL查询今日、昨日、最近七天的数据
MySQL查询今日、昨日、最近七天的数据
302 0
|
消息中间件 Kafka API
Kafka - 图解生产者消息发送流程
Kafka - 图解生产者消息发送流程
375 0
|
XML 安全 Android开发
Android View Binding使用
Android View Binding使用
206 0
|
机器学习/深度学习 自然语言处理 数据处理
机器学习实现恶意URL检测实战
恶意URL检测的方法很多,这里介绍通过机器学习分析URL文本分词词频来检测恶意URL。训练的数据集为开源数据集,通过机器学习训练检测模型,然后做了部分工程化的应用,将模型持久化,在应用的时候加载进来直接应用,不用重新进行训练。通过接口调用实现恶意URL检测预测判断。 恶意URL检测,对应与机器学习是个分类问题,这里分别用逻辑回归和SVM支持向量机分类模型进行模型实现。
806 0