android基础组件--CardView


Android在 5.0中添加了阴影效果主要通过CardView来实现,在低版本中通过android.support.v7.widget.CardView来实现。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/包名"
    android:id="@+id/rlListItemGame"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="8dp"
    android:paddingRight="8dp"
    android:paddingTop="2dp" >

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:cardBackgroundColor="@android:color/white"
        app:cardCornerRadius="3dp"
        app:cardElevation="2dp"
        app:cardUseCompatPadding="true" >

可以看到上面的代码中多了三个app:属性,

app:cardCornerRadius设置圆角大小,

app:cardElevation设置阴影大小,

app:cardBackgroundColor="#fff000" 设置背景色

android:foreground=”?android:attr/selectableItemBackground”可以使CardView点击产生波纹的效果,有触摸点向外扩散

app:cardUseCompatPadding,设置分割效果,它在5.0以下的系统中默认是true,但在5.0系统中默认为false,如果不设置 app:cardUseCompatPadding=”true”的话会造成在5.0系统的Android手机上不能看到阴影效果。
最后一定要记得加上

xmlns:app="http://schemas.android.com/apk/res-auto"

CardView的兼容lib(eclipse可用)http://download.csdn.net/detail/zhong1113/8707351


2. 案例使用

cardview相当于个升级版的FrameLayout

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:app="http://schemas.android.com/apk/res-auto"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="wrap_content"  
  6.     app:cardCornerRadius="3dp"  
  7.     app:cardBackgroundColor="#fff000"  
  8.     app:cardUseCompatPadding="true"  
  9.     app:cardElevation="2dp">  
  10.   
  11.     <RelativeLayout  
  12.         android:padding="10dp"  
  13.         android:layout_width="match_parent"  
  14.         android:layout_height="wrap_content">  
  15.   
  16.         <LinearLayout  
  17.             android:id="@+id/ll"  
  18.             android:layout_width="match_parent"  
  19.             android:layout_height="wrap_content"  
  20.             android:gravity="center_vertical"  
  21.             android:orientation="horizontal"   >  
  22.   
  23.             <ImageView  
  24.                 android:id="@+id/icon"  
  25.                 android:layout_width="wrap_content"  
  26.                 android:layout_height="wrap_content"  
  27.                 android:src="@mipmap/ic_launcher" />  
  28.   
  29.             <TextView  
  30.                 android:id="@+id/text"  
  31.                 android:layout_width="wrap_content"  
  32.                 android:layout_height="wrap_content"  
  33.                 android:text="哈哈哈哈啊" />  
  34.   
  35.         </LinearLayout>  
  36.   
  37.     </RelativeLayout>  
  38.   
  39. </android.support.v7.widget.CardView> 

参考

http://blog.csdn.net/jdsjlzx/article/details/49511215





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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值