开源的RippleLayout,点击产生波浪涟漪效果
来源:互联网 发布:如何看待网络言论作文 编辑:程序博客网 时间:2024/05/21 03:24
开源的RippleLayout,点击产生波浪涟漪效果
有些app点击ListView的条目或按钮或页面会有波浪的涟漪效果,本文使用一个自定义View实现这个效果,这个自定义View是继承了FrameLayout,里面只能放一个布局或控件,否则会报错!
效果:
虽然谷歌也有了点击产生涟漪效果的API和资源文件,但是需要最低5.0的SDK等级(21)才能使用,注意是最低,不是正在编译的版本的等级。反正Eclipse中是不能识别这个资源了,Studio就不知道了。
网上也有很多这个开源的View的设计,有的是直接继承View,有的是继承Relativelayout,但是,有些是存在问题的,比如,我之前试过一个它会阻断了ListView的Item点击回调的监听!
这个开源的RippleLayout使用起来也是非常简单的,可以直接把它当作一个FrameLayout使用,就会有点击后产生波浪涟漪效果了,当然也是可以设置一些属性。
使用:
导入一个自定义View的类RippleLayout,代码太多,就不贴出来了
添加attrs的自定义属性
使用示例1,什么都不设置:
<?xml version="1.0" encoding="utf-8"?> <!--注意是自定义View的导入--><com.example.ripples.RippleLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="50dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/text" android:layout_centerInParent="true" /> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_launcher" /> </RelativeLayout></com.example.ripples.RippleLayout>
使用示例2,设置一些属性:
<?xml version="1.0" encoding="utf-8"?> <com.example.ripples.RippleLayout 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="60dp" app:mrl_rippleColor="#ffffff00" //设置波浪涟漪的颜色 app:mrl_rippleDimension="10dp" //涟漪刚开始产生的范围大小,。。dp app:mrl_rippleOverlay="true" //涟漪产生的波纹是否会覆盖,默认false app:mrl_rippleAlpha="0.5" //涟漪产生的波纹的透明度,1表示完全显示,0就不显示,0.2就显示很浅的一点 app:mrl_rippleDuration="2000" //涟漪产生的时间长短,毫秒数 app:mrl_rippleFadeDuration="1000" //涟漪消失过程的时间长短,毫秒数 app:mrl_rippleHover="true" //涟漪是否盘旋显示,好像没啥效果 app:mrl_rippleBackground="#ff00" //背景颜色,和backgroud一样 app:mrl_rippleDelayClick="true" //是否延迟点击,没啥作用 app:mrl_ripplePersistent="false" //是否是显示涟漪后的效果,就是颜色变了一直保持那种颜色 app:mrl_rippleRoundedCorners="1dp" //涟漪图形的圆角大小,一般也不用 > <TextView android:layout_width="match_parent" android:layout_height="40dp" android:gravity="center" android:textSize="25sp" android:clickable="true" android:onClick="clickText" android:layout_margin="10dp" android:text="页面底部的按钮" /> </com.example.ripples.RippleLayout>
当然你也可以在RippleLayout类里面修改一些属性,让所有的点击效果都一样,就不用在多个自定义布局中设置属性了!
源码查看或下载的地址:https://github.com/liwenzhi/RippleLayout
共勉:身体是革命的本钱,保重好身体,以后才能干大事业!
阅读全文
1 0
- 开源的RippleLayout,点击产生波浪涟漪效果
- 自定义点击产生涟漪效果
- button 点击的涟漪效果
- RippleEffect 产生涟漪效果的空间
- android的Material Design点击涟漪效果
- 自定义view点击产生涟漪
- 艺术般的波浪点击反馈效果
- 按钮点击波浪效果
- 兼容Android API 2.X的涟漪点击效果
- 鼠标点击的涟漪效果(unity&shader)
- 能产生波浪效果的背景图片控件,可以自定义颜色,波浪扩展的速度,波浪的圈数。
- kitlin recycler item点击涟漪效果 应用于各种点击效果
- CSS3做涟漪的效果
- Android长按Button按钮,产生涟漪效果
- Android实现点击产生气泡的效果
- 安卓点击涟漪
- ios点击产生波纹效果
- 点击图片产生水波的动画效果代码展示
- Barracuda
- 在项目启动时(无request)获取Tomcat端口号
- Set集合
- S2SM集成Shiro-登录验证
- 5th 【基础题】组合三角形
- 开源的RippleLayout,点击产生波浪涟漪效果
- ecshop之transport和jquery冲突之完美解决方案
- 【实践】端到端的OCR:验证码识别
- Java菜鸟成长之路__Day_2_Java_方法
- Redis原理详解
- Android Fingerprint -- Enroll流程
- vue2 子组件调用父组件中的方法
- centos7 最小化安装后无法上网,需要先开启网络服务
- linux之nautilus .命令浏览当前文件目录