recycler添加ripple效果
2016-03-27 17:47
274 查看
1.系统5.0以上,创建drawable-21包,添加xml文件;
其中:
recycler_rectangle.xml
recycler_bg.xml
2.系统5.0以下在drawble中添加:recycler_bg.xml
3.需要在onBindViewHolder中添加:
4.注意:当为控件设置的点击事件占满item时,不能显示波纹;
感谢:http://blog.csdn.net/qq_29262849/article/details/50449044
其中:
recycler_rectangle.xml
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#FFFFFF" /> </shape>
recycler_bg.xml
<?xml version="1.0" encoding="utf-8"?> <!-- ripple 是5.0才出现的新标签--> <ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="#cfd8dc" ><!-- 点击出现的水波纹的颜色 --> <item android:drawable="@drawable/recycler_rectangle"/> </ripple>
2.系统5.0以下在drawble中添加:recycler_bg.xml
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" > <shape android:shape="rectangle"> <solid android:color="#cfd8dc"></solid> </shape> </item> </selector>
3.需要在onBindViewHolder中添加:
<pre name="code" class="java">holder.itemView.setBackgroundResource(R.drawable.recycler_bg);<span style="white-space:pre"> </span>//<span style="font-family: Arial, Helvetica, sans-serif;">只有该代码没有效果,必须要有点击事件</span> holder.itemView.setOnClickListener();<span style="white-space:pre"> </span>
<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"> </span>
4.注意:当为控件设置的点击事件占满item时,不能显示波纹;
感谢:http://blog.csdn.net/qq_29262849/article/details/50449044
相关文章推荐
- js中typeof与instanceof用法
- C++中的static关键字(杂谈)
- Handler的学习之路--Handler的用法(1)
- 个人电影分享
- Oracle 删除重复行
- 子数组2
- java小练习:输入一个字符,判断该字符是数字?英文字母?还是其他字符
- @Resource @Autowired的注解注入及区别
- day10 面试 重定向和转发的区别
- CentOS 6.4x64安装部署zabbix-2.4.5
- poj 1611 The Suspects
- SNMP&CMIP两种网络管理协议
- Eclipse快捷键大全(转载)
- 利用命令模式模拟烤肉店点餐 C++
- linux 清空串口缓存
- 查询02_程序包锁的处理
- 第七道ACM程序题
- Is-a vs. is-like-a relationships("是一个"与"像是一个")关系
- 【剑指Offer学习】【面试题56:链表中环的入口结点】
- Bresenham算法