这个效果是个老效果了,不过这种水波纹Ripple只能在Android 5.0以上才能支持,要向下兼容少不了。网上找了一些感觉好用的不多,于是自己写了一个。
这个效果原理很简单,只要确定点击的位置,然后做一个圆圈放大的效果。还有一点,点击layout后可以直接触发在它里面的view的点击事件。
在使用时,设置圆形的最小半径和最大半径,还有颜色,透明度。useCenter属性是指,是否使用布局自身的中心点作为中心来显示ripple效果,false时就是用手指点击的位置作为中心点。
<com.arjinmc.rippleeffectlayout.RippleEffectLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:minRadius="100"
app:maxRadius="800"
app:colorAlpha="0.2"
app:color="#000000"
app:useCenter="true"
android:padding="16dp">
<CheckBox
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ATTENTION!"
/>
</com.arjinmc.rippleeffectlayout.RippleEffectLayout>
代码比较简单,不详细介绍了。具体看源码吧。