android 5.0新特性CardView教程
来源:互联网 发布:c语言void什么意思 编辑:程序博客网 时间:2024/04/27 04:43
CardView 是android5.0新加入的特性,大家先别着急,由于谷歌出了cardview的兼容包,也就是android.support.v7.widget.CardView包,所以在5.0以下的系统也可以运行这个效果。什么是CardView ?就是在View的外面加上一个类似如卡片的阴影,下面放代码。
<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"看看
下面是效果图:
明显圆角变大了。
0 0
- android 5.0新特性CardView教程
- Android新特性v7 - CardView
- Android Studio中使用Android5.0新特性CardView
- Android新特性之CardView的简单使用
- Android新特性之CardView的简单使用
- Android新特性之CardView的简单使用
- Android新特性之CardView的简单使用
- Android新特性之CardView的简单使用
- Android新特性之CardView的简单使用
- android新特性:RecyclerView与CardView配合使用
- Android新特性之CardView的简单使用
- Android新特性之RecyclerView和CardView联合使用
- (转)Android新特性之CardView的简单使用
- Android新特性之RecyclerView和CardView联合使用
- android新特性:RecyclerView与CardView配合使用
- Android新特性之CardView的简单使用
- Android新特性之CardView的简单使用
- Android新特性之CardView的简单使用
- 芒果iOS之显示隐藏资源库Library
- phalapi-进阶篇2(DI依赖注入和单例模式)
- 磁珠的作用
- CSS学习笔记之<z-index属性>
- AVAudioRecorder录音和AVAudioPlayer播放
- android 5.0新特性CardView教程
- 排序算法(五):冒泡排序
- 基于PhalApi的DB集群拓展 V0.1bate
- 百度echarts后台Java封装小实例
- 线程1: i++; i++; 线程2: i+=2; 的问题 (2013年某公司笔试题目)
- 给你的JAVA程序配置参数(Properties的使用)
- Content-disposition
- Foundation框架下的结构体
- 单链表的的逆置(带头结点)