android基础组件--CardView
来源:互联网 发布:福建随行软件下载 编辑:程序博客网 时间:2024/06/08 01:35
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
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- app:cardCornerRadius="3dp"
- app:cardBackgroundColor="#fff000"
- app:cardUseCompatPadding="true"
- app:cardElevation="2dp">
- <RelativeLayout
- android:padding="10dp"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <LinearLayout
- android:id="@+id/ll"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:orientation="horizontal" >
- <ImageView
- android:id="@+id/icon"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@mipmap/ic_launcher" />
- <TextView
- android:id="@+id/text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="哈哈哈哈啊" />
- </LinearLayout>
- </RelativeLayout>
- </android.support.v7.widget.CardView>
参考
http://blog.csdn.net/jdsjlzx/article/details/49511215
0 0
- android基础组件--CardView
- Android卡片组件(CardView)
- Android基础控件—CardView
- Android组件之CardView的基本使用
- Android Design风格组件之CardView
- android 卡片式视图组件 cardview的使用
- android cardview
- Android CardView
- RecyclerView + CardView 基础练习
- android基础UI组件
- android基础 四大组件
- Android基础UI组件
- Android中的基础组件
- Android基础和组件
- Android -- Activity组件基础
- Android 基础组件
- Android RecyclerView And CardView
- Android 5.0 CardView 应用
- rdlc报表预览打印
- ubuntu1404安装简记
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming!
- HttpClient 实现get和post请求的过程
- 《Android开发艺术探索》阅读笔记(一)、activity生命周期 及 启动模式
- android基础组件--CardView
- 【已解决】Android中给EditText添加的TextWatcher中的onTextChanged始终被调用(被执行多次)
- ListView中TextView的适配
- jquery 点击旋转效果,点击图片旋转360度
- 【Usaco 2007 Dec gold】队列变换
- 替换空格
- poj2996
- csu1508 地图的四着色(剪枝+BFS DFS)
- 浅谈构造函数与析构函数的调用顺序