首页 > 移动平台 > 详细

《Android应用开发:CardView的使用》

时间:2015-10-13 10:52:55      阅读:350      评论:0      收藏:0      [点我收藏+]

在使用CardVIew之前,要明白CardView是个什么东西。CardView如Linearlayout、Framelayout一样都是ViewGroup,即其他控件的容器。CardView继承于Framelayout,所以Framelayout的属性他都有,同时CardView还有几个特殊的属性:

在API21(Android L)等级以上拥有属性elevation,意为CardView的Z轴阴影,只有L平台有效。只能通过xml中的elevation属性指定;

其余(2.0以上)有属性cardBackgroundColor,意为CardView的卡片颜色,只能通过xml的cardBackgroundColor进行指定;

其余(2.0以上)有属性cardConerRadius,意为CardView卡片的四角圆角矩形程度,单位dimen(dp px sp),可以通过xml指定,也可以通过代码中的setRadius指定。

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:app="http://schemas.android.com/apk/res-auto"  
    android:id="@+id/cardview"  
    app:cardCornerRadius="8dp"  
    app:cardBackgroundColor="@color/black"  
    android:layout_margin="8dp"  
    android:layout_height="80dp"  
    android:layout_width="match_parent">  
  
    <TextView  
        android:text="TextView in CardView"  
        android:layout_gravity="center"  
        android:textSize="26sp"  
        android:textColor="@color/l_white"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content" />  
</android.support.v7.widget.CardView>

上面也提到CardView像一个FragmentLayout,所以他里面的内容会有层级结构,大家要注意。并且与recyclerview联合使用的话,会有很多意想不到的效果哟


《Android应用开发:CardView的使用》

原文:http://my.oschina.net/u/1269023/blog/516104

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!