简约才是王道? CardView 的使用

发现个好看的东东 CardView。他在support v7包中~~

顾名思义就是卡片view。能够设置阴影,圆角,等等。。

样子是这种:
这里写图片描写叙述

或者你还能够放到listview里 是这种:

http://blog.csdn.net/wingichoy/article/details/50687727

怎么使用

在xml文件里 增加一个CardView

 <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        <--!设置CardView的背景色-->
        card_view:cardBackgroundColor="#303069"

        <--!设置CardView的半径-->
        card_view:cardCornerRadius="10dp"
        card_view:cardPreventCornerOverlap="true"
        card_view:cardUseCompatPadding="true"

        <--!设置CardView的padding-->
        card_view:contentPadding="10dp">
        <TextView
            android:text="我是CardView"

            android:textColor="#fff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

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

里面能够包裹内容。通过观察源代码我们发现,CardView事实上是一个FrameLayout。所以使用方式跟FrameLayout同样

public class CardView extends FrameLayout implements CardViewDelegate {
}

或者你也能够用于ListView~~ 反正非常简约美观就是啦~~

这里写图片描写叙述

以后再遇到什么圆角的需求,就能够用这个完毕。而不是什么PorterDuffXferMode了~~

假设你喜欢我的博客。请关注我~

原文地址:https://www.cnblogs.com/lytwajue/p/7373298.html