不断学习,做更好的自己!💪
视频号 | CSDN | 简书 |
---|---|---|
欢迎打开微信,关注我的视频号:程序员朵朵 | 点我 | 点我 |
前言
引入 material 包:
implementation 'com.google.android.material:material:1.2.1'
属性
属性 | 含义 |
---|---|
cardBackgroundColor | 设置卡片的背景色 |
cardCornerRadius | 设置卡片的圆角 |
cardElevation | 设置卡片的阴影 |
cardUseCompatPadding | 是否添加padding |
cardPreventCornerOverlap | 在v20和v20以前的版本添加padding,防止CardView的内容和圆角相交 |
使用
-
效果图
-
布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<com.google.android.material.card.MaterialCardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="3dp"
app:cardElevation="3dp"
android:clickable="true"
android:foreground="?attr/selectableItemBackground"
app:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="300dp"
android:scaleType="centerCrop"
android:src="@mipmap/meizi"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24sp"
android:text="Material Design"
android:textColor="@color/black"
android:layout_marginTop="16dp"
android:paddingRight="16dp"
android:paddingLeft="16dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginTop="6dp"
android:paddingRight="16dp"
android:paddingLeft="16dp"
android:text=" material metaphor is the unifying theory of a rationalized space and a system of motion."
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="16sp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/orange"
android:textSize="24sp"
android:text="SHARE"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/orange"
android:textSize="24sp"
android:text="EXPLORE"
android:layout_marginLeft="20dp"
/>
</LinearLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</LinearLayout>