android 5.0新特性CardView教程
2015-11-07 21:52
555 查看
CardView 是android5.0新加入的特性,大家先别着急,由于谷歌出了cardview的兼容包,也就是android.support.v7.widget.CardView包,所以在5.0以下的系统也可以运行这个效果。什么是CardView ?就是在View的外面加上一个类似如卡片的阴影,下面放代码。
这是原来的代码。下面是运行效果:
![](http://img.blog.csdn.net/20151107214652057?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
然后,只需要在Relativelayout上一行加上几行代码,就能实习卡片效果:
代码
实现效果:
![](http://img.blog.csdn.net/20151107214550412?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
其中:
card_view:cardCornerRadius="1dp" 是设置圆角效果。
作为对比,我们改成
card_view:cardCornerRadius="10dp"看看
下面是效果图:
![](http://img.blog.csdn.net/20151107215016050?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
明显圆角变大了。
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp" > <ImageView android:id="@+id/pic" android:layout_width="match_parent" android:layout_height="wrap_content" android:scaleType="centerCrop" /> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/pic" android:layout_centerHorizontal="true" android:gravity="center" android:textColor="#212121" android:textSize="16sp" /> </RelativeLayout>
这是原来的代码。下面是运行效果:
然后,只需要在Relativelayout上一行加上几行代码,就能实习卡片效果:
代码
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="5dp" card_view:cardBackgroundColor="@color/cardview_light_background" card_view:cardCornerRadius="1dp" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="5dp" > <ImageView android:id="@+id/pic" android:layout_width="match_parent" android:layout_height="wrap_content" android:scaleType="centerCrop" /> <TextView android:id="@+id/name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/pic" android:layout_centerHorizontal="true" android:gravity="center" android:textColor="#212121" android:textSize="16sp" /> </RelativeLayout> </android.support.v7.widget.CardView>
实现效果:
其中:
card_view:cardCornerRadius="1dp" 是设置圆角效果。
作为对比,我们改成
card_view:cardCornerRadius="10dp"看看
下面是效果图:
明显圆角变大了。
相关文章推荐
- SEAndroid与SEpolicy Language简介
- Android button 点击变色,圆角
- Android背景选择器selector
- Android 百度地图SDK v_3_4_0学习笔记(一)环境搭建
- ionic 解决android 中tabs 在上面的问题。
- android 的oermission权限
- Android系统中的Activity简介
- Android开书籍推荐
- Android Service完全解析,关于服务你所需知道的一切
- [Android]View响应屏幕触摸事件
- Android进阶之_实现滑动的7种方式详解
- Android 正则表达式 Pattern 和 Matcher
- Android存储-sd卡存储
- Android 启动Activity两个属性 .MAIN .LAUNCHER
- android.os.NetworkOnMainThreadException
- android中handle的用法
- Android组件之间的通信
- android沉浸式状态栏实现
- Android 适配器委托模式
- android移植pppoe拨号上网的全过程