总结一下 Material Design控件 cradview 的用法

本文主要介绍CardView的使用,CardView是继承自FrameLayout,

使用比较简单,只需要用CardView包含其他View就可以实现卡片效果了。


加入依赖库 

compile 'com.android.support:cardview-v7:22.2.0'

在布局中使用

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    >


    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        app:cardElevation="@dimen/cardview_compat_inset_shadow"
        app:cardCornerRadius="@dimen/cardview_default_radius"
        app:cardMaxElevation="@dimen/cardview_default_elevation"
        >


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:padding="20dp">

            <TextView
                android:id="@+id/textview1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:text="@string/trytry"
                android:textColor="@android:color/holo_blue_dark"
                android:textSize="25dp"

                />

            <TextView
                android:id="@+id/desc"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:text="好多东西"
                android:textColor="@android:color/holo_green_dark" />

        </LinearLayout>


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


</LinearLayout>

其中 

  • app:cardBackgroundColor 设置CardView背景颜色
  • app:cardCornerRadius 设置CardView圆角大小
  • app:cardElevation 设置CardView阴影高度


运行效果:





  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值