Android Design风格组件之CardView

如何添加?

I. 在 build.gradle 里引入 cardview 库。


dependencies {  
  compile 'com.android.support:cardview-v7:X.X.X' // where X.X.X version
}

II. 在 layout.xml 里声明 card ,并用它包裹其他的 view 。

<android.support.v7.widget.CardView  
    android:layout_width="match_parent"
    android:layout_height="200dp">

    <TextView
        android:text="Hello World!"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

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

给 CardView 的父布局增加属性 android:clipToPadding=”false” ,可以保证 CardView 的阴影不被裁剪掉。

如何设置样式?

I. 在 styles.xml 文件里声明你自定义的样式。

<style name="MyCardViewStyle" parent="Theme.AppCompat.Light">  
    <item name="cardCornerRadius">2dp</item>
    <item name="cardElevation">2dp</item>
    <item name="contentPaddingBottom">24dp</item>
    <item name="contentPaddingTop">24dp</item>
    <item name="contentPaddingLeft">16dp</item>
    <item name="contentPaddingRight">16dp</item>
    <item name="cardBackgroundColor">@color/indigo</item>
</style>  

II. 设置你的 CardView 的 style 属性值为自定义的样式。

<android.support.v7.widget.CardView  
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    style="@style/MyCardViewStyle">

Ⅲ. 效果图

这里写图片描述

其他连接
BottomNavigationBar:实现Android特色底部导航栏

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值