【Android -- Material Design】MaterialCardView 的基本使用

不断学习,做更好的自己!💪

视频号CSDN简书
欢迎打开微信,关注我的视频号:程序员朵朵点我点我

前言

官网:MaterialCardView
1625033671(1).png

引入 material 包:

implementation 'com.google.android.material:material:1.2.1'

属性

属性含义
cardBackgroundColor设置卡片的背景色
cardCornerRadius设置卡片的圆角
cardElevation设置卡片的阴影
cardUseCompatPadding是否添加padding
cardPreventCornerOverlap在v20和v20以前的版本添加padding,防止CardView的内容和圆角相交

使用

  1. 效果图
    meizi.jpg

  2. 布局

<?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>
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Kevin-Dev

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值