高级UI-CardView
CardView是在Android 5.0推出的新控件,为了兼容之前的版本,将其放在了v7包里面,在现在扁平化设计潮流的驱使下,越来越多的软件使用到了CardView这一控件,那么这篇文章就来看看CardView怎么使用吧
CardView的特有属性
cardBackgroundColor
背景色
cardCornerRadius
边缘弧度数
cardElevation
高度
cardMaxElevation
最大高度
cardUseCompatPadding
设置内边距
cardPreventCornerOverlap
防止卡片内容和边角的重叠
contentPadding
内边距
contentPaddingLeft
内左边距
contentPaddingRight
内右边距
contentPaddingTop
内上边距
contentPaddingBottom
内下边距
CardView使用
由于CardView的使用比较简单,这里不再过多描述
使用前导入依赖
implementation 'com.android.support:cardview-v7:25.4.0'
文字
<LinearLayout 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="match_parent"
android:gravity="center"
tools:context=".MainActivity">
<android.support.v7.widget.CardView
android:layout_width="300dp"
android:layout_height="200dp"
app:cardBackgroundColor="@android:color/holo_green_light"
app:cardCornerRadius="8dp"
app:cardElevation="10dp"
app:contentPadding="20dp"
android:layout_margin="0dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/darker_gray"
android:text="card view text"
android:textColor="@android:color/white" />
</android.support.v7.widget.CardView>
</LinearLayout>
效果如下
图片
<LinearLayout 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="match_parent"
android:gravity="center"
tools:context=".MainActivity">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:cardElevation="10dp"
app:contentPadding="20dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@mipmap/ic_launcher" />
</android.support.v7.widget.CardView>
</LinearLayout>
效果如下
适配注意点
- 边框圆角效果
5.x 图片和布局都可以很好的呈现圆角效果,图片也变圆角了
4.x 图不能变成圆角,如果要做成5.x一样的效果:通过加载图片的时候自己去处理成圆角 - 阴影效果
app:cardCornerRadius="10dp"<!--圆角(半径值越大圆角就越明显)-->
app:cardElevation="10dp" <!--阴影效果(值越大阴影效果越明显)-->
- 5.x上有Ripple水波纹效果(低版本自定义)
android:foreground="?attr/selectableItemBackground"
android:clickable="true"
- 5.x实现按下的互动效果下沉,松开弹起 - Z轴位移效果(低版本自定义)
android:stateListAnimator="@drawable/translation"
android:clickable="true"
- 可以设置内容的内边距
app:contentPadding="5dp"
细节:
5.x上面,边距阴影比较小,需要手动添加边距16dp
4.x上面,边距太大, 手动修改边距0dp(原因:兼容包里面设置阴影效果自动设置了margin来处理16dp)
translation.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueTo="10dp"
android:valueType="floatType" />
</item>
<item>
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueTo="0dp"
android:valueType="floatType" />
</item>
</selector>
高级UI-CardView的更多相关文章
- firefox 扩展开发笔记(三):高级ui交互编程
firefox 扩展开发笔记(三):高级ui交互编程 前言 前两篇链接 1:firefox 扩展开发笔记(一):jpm 使用实践以及调试 2:firefox 扩展开发笔记(二):进阶开发之移动设备模拟 ...
- Android 高级UI设计笔记07:RecyclerView 的详解
1. 使用RecyclerView 在 Android 应用程序中列表是一个非常重要的控件,适用场合非常多,如新闻列表.应用列表.消息列表等等,但是从Android 一出生到现在并没有非常 ...
- iOS开发——高级UI&带你玩转UITableView
带你玩装UITableView 在实际iOS开发中UITableView是使用最多,也是最重要的一个控件,如果你不会用它,那别说什么大神了,菜鸟都不如. 其实关于UItableView事非常简单的,实 ...
- 高级UI晋升之自定义View实战(六)
更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章将从Android 自定义属性动画&Camera动画来介绍自定义V ...
- 高级UI晋升之布局ViewGroup(四)
更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章将从LinearLayout.RelativeLayout.FrameLa ...
- 高级UI晋升之常用View(三)中篇
更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章将从ViewPager来介绍常用View:文章目录 一.简介 二.基本使用 ...
- 高级UI晋升之常用View(三)上篇
更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680本篇文章将先从以下两个内容来介绍常用View: [RecycleView] [Ca ...
- 高级UI晋升之View渲染机制(二)
更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680 优化性能一般从渲染,运算与内存,电量三个方面进行,今天开始说聊一聊Android ...
- 高级UI晋升之触摸事件分发机制(一)
更多Android高级架构进阶视频学习请点击:https://space.bilibili.com/474380680 0. 前言 鉴于安卓分发机制较为复杂,故分为多个层次进行讲解,分别为基础篇.实践 ...
- Android 高级UI设计笔记21:Android SegmentView(分段选择控件)
1. 分段控制(SegmentView) 首先我们先看看什么是SegmentView的效果,如下: 分段控制这个View控件是ios7的分段控制,和QQ消息页面顶部的效果一样,android没有这个控 ...
随机推荐
- C# 分割字符串 分隔符是字符串的情况
string[] arr = System.Text.RegularExpressions.Regex.Split(str, "\r\n");
- 洛谷 P2010 回文日期 题解
P2010 回文日期 题目描述 在日常生活中,通过年.月.日这三个要素可以表示出一个唯一确定的日期. 牛牛习惯用88位数字表示一个日期,其中,前44位代表年份,接下来22位代表月 份,最后22位代表日 ...
- (24)打鸡儿教你Vue.js
学习Vue基础语法 Vue中的组件 Vue-cli的使用 1.使用Vue2.0版本实现响应式编程 2.理解Vue编程理念与直接操作Dom的差异 3.Vue常用的基础语法 4.使用Vue编写TodoLi ...
- Dart 日期时间 DateTime
1.获取当前时间 var now = new DateTime.now(); print(now); // 2019-06-20 16:59:05.560543 2.设置时间 var d =new D ...
- 模板 - 数学 - 数论 - 扩展Euler定理
费马(Fermat)小定理 当 \(p\) 为质数,则 \(a^{p-1}\equiv 1 \mod p\) 反之,费马小定理的逆定理不成立,这样的数叫做伪质数,最小的伪质数是341. 欧拉(Eule ...
- Nginx服务配置文件介绍
LNMP架构应用实战——Nginx服务配置文件介绍 nginx的配置文件比较简单,但功能相当强大,可以自由灵活的进行相关配置,因此,还是了解下其配置文件的一此信息 1.Nginx服务目录结构介绍 安装 ...
- BAT文件语法和技巧(bat文件的编写及使用)
比较有用的东西 首先,批处理文件是一个文本文件,这个文件的每一行都是一条DOS命令(大部分时候就好象我们在DOS提示符下执行的命令行一样),你可以使用DOS下的Edit或者Windows的记事本(no ...
- 熔断机制hystrix
一.问题产生 雪崩效应:是一种因服务提供者的不可用导致服务调用者的不可用,并将不可用逐渐放大的过程 正常情况下的服务: 某一服务出现异常,拖垮整个服务链路,消耗整个线程队列,造成服务不可用,资源耗尽: ...
- MYSQL 神奇的操作insert into test select * from test;
将16行数据复制一份插入数据库,变成32行
- 20190729 将博客搬至CSDN
为更方便技术交流, 现将博客园内容搬迁至csdn, https://blog.csdn.net/lxw1844912514