Android UI——Material Design ——CardView

Android Material Design CardView

Android在新的Material Design中加入了一个卡片式的效果。以前在不使用CardView的时候我们想要实现卡片布局的效果只能够自定义drawable或者自定义图片。这样就会导致只要想实现圆角的时候,就需要写一大堆的drawable圆角定义。奈何设计师总是偏爱于圆角的效果。在有了Design的CardView后我们再实现这样的效果就简单一些了

CardView使用

导入Android Design包 android.support.v7.widget.CardView

     implementation 'com.android.support:design:28.0.0'

布局文件中使用

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <android.support.v7.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="300dp"
        android:layout_height="200dp"
        app:cardCornerRadius="10dp"
        app:cardElevation="10dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            android:orientation="vertical">

            <android.support.v7.widget.AppCompatImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@mipmap/ic_launcher" />

            <android.support.v7.widget.AppCompatTextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="12345"
                />
        </LinearLayout>

    </android.support.v7.widget.CardView>

</android.support.constraint.ConstraintLayout>
  • 显示效果

    《Android UI——Material Design ——CardView》 cardView效果

一些属性

属性说明
cardBackgroundColor卡片背景颜色
cardCornerRadius卡片的圆角大小
cardElevation阴影的大小
cardMaxElevation阴影最大高度
contentPadding卡片内容与边距的间隔
    原文作者:So_ProbuING
    原文地址: https://www.jianshu.com/p/7c07fff22b31
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞