MD的特色之一就是"有意义的动画效果",让动画符合物理世界的规律,而不是杂乱无章,华而不实。
点击事件产生的波纹效果就是其中之一。
那么,先让我们看一下什么是波纹效果:
touch_feedback.gif
可以看出,点击变得更具有质感而不是简单的使条目变色。
让我们在RecyclerView上做下实验
RecyclerView默认点击是没有任何效果的
touch1.gif
MD之前,我们为条目添加点击效果是这样的
新建drawable/touch_bg.xml
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@color/super_light_grey" android:state_pressed="true"/> <item android:drawable="@color/super_light_grey" android:state_focused="true"/> <item android:drawable="@color/white"/></selector>
然后为点击的条目设置android:background="@drawable/touch_bg"
在点击条目的时候便可以看到条目变色
touch2.gif
但是我们现在想要的是波纹效果,这里要注意,波纹效果只在5.0以上的设备生效
所以我们需要新建drawable-v21/touch_bg.xml
<?xml version="1.0" encoding="utf-8"?><ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@color/line_grey"> <item android:drawable="@color/white"/></ripple>
之后,便可以看到期待的波纹效果。
touch3.gif
代码以及第一张图片均参考项目Animate
希望能够对你有所帮助
點(diǎn)擊查看更多內(nèi)容
為 TA 點(diǎn)贊
評(píng)論
評(píng)論
共同學(xué)習(xí),寫下你的評(píng)論
評(píng)論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦