您的位置:首页 > 其它

recycler添加ripple效果

2016-03-27 17:47 274 查看
1.系统5.0以上,创建drawable-21包,添加xml文件;

其中:

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: