简介:Material Design中有一种很个性的设计概念:卡片式设计(Cards),Cards拥有自己独特的UI特征,在v7包中引进了一种全新的控件CardView,用来实现这种 Cards UI 的设计.CardView继承自FrameLayout,它是一个带圆角背景和阴影的FrameLayout.
添加依赖
compile 'com.android.support:cardview-v7:25.3.1'
1、使用
CardView本质上属于FrameLayout,不同的是,它多了很多"特效"(圆角、阴影等).
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:cardCornerRadius="12dp"
app:cardElevation="12dp" >
<ImageView android:layout_width="284dp"
android:layout_height="228dp"
android:scaleType="fitXY"
android:src="@mipmap/img" />
</android.support.v7.widget.CardView></RelativeLayout>
被CardView包裹的ImageView有明显的圆角和阴影,这就是CardView最重要的两条属性了.
app:cardCornerRadius=" " 圆角的半径,效果就是上面四个角的弧度
app:cardElevation=" " 阴影大小
2、关于Z轴的概念
Android5.0 引入了Z轴的概念,可以让组件呈现3D效果.