按钮有一道光闪过的特效 并且定时左右晃动

这个效果是在博客上找的 但是我更改了一下内容 具体向下细看
直接上效果

先是制作一个闪光的图片

<selector xmlns:android="http://schemas.android.com/apk/res/android"><item><shape><gradient android:angle="180"android:centerColor="#4CFFFFFF"android:endColor="#00000000"android:startColor="#00000000" /></shape></item>
</selector>
public class MatrixImageView extends ImageView {private Bitmap mBitmap;private Matrix mMatrix;public MatrixImageView(Context context, @Nullable AttributeSet attrs) {super(context, attrs);mBitmap = getBitmap(context, R.drawable.light_slide_btn);mMatrix = new Matrix();}@Overrideprotected void onDraw(Canvas canvas) {//画经过Matrix变化后的图canvas.drawBitmap(mBitmap, mMatrix, null);super.onDraw(canvas);}@Overridepublic void setScaleType(ImageView.ScaleType scaleType) {super.setScaleType(ScaleType.MATRIX);}@Overridepublic void setImageMatrix(Matrix matrix) {this.mMatrix.set(matrix);super.setImageMatrix(matrix);}private static Bitmap getBitmap(Context context, int vectorDrawableId) {Bitmap bitmap = null;if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP) {Drawable vectorDrawable = context.getDrawable(vectorDrawableId);bitmap = Bitmap.createBitmap(Utils.dp2px(context, 62),Utils.dp2px(context, 62), Bitmap.Config.ARGB_8888);Canvas canvas = new Canvas(bitmap);vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());vectorDrawable.draw(canvas);} else {bitmap = BitmapFactory.decodeResource(context.getResources(), vectorDrawableId);}return bitmap;}
}

然后闪光的图片就出来了 在制作移动的效果使用动画

<set xmlns:android="http://schemas.android.com/apk/res/android"><translateandroid:duration="2000"android:fromXDelta="0"android:fromYDelta="0"android:toXDelta="1080"android:toYDelta="0"android:repeatCount="1000"android:interpolator="@android:anim/cycle_interpolator"android:repeatMode="restart"/>
</set>

然后就是连接起来

代码使用

ImageView ivMartix = findViewById(R.id.iv_matrix);Matrix matrix = new Matrix();matrix.setSkew(-1, 0);ivMartix.setImageMatrix(matrix);animation = AnimationUtils.loadAnimation(this, R.anim.l2r_btn_light_slide);ivMartix.startAnimation(animation);

xml布局

 <LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"><Buttonandroid:id="@+id/subscription2_popup_buy_btn"android:layout_width="match_parent"android:layout_height="62dp"android:layout_marginLeft="46dp"android:layout_marginTop="20dp"android:layout_marginRight="46dp"android:layout_marginBottom="30dp"android:background="@drawable/subscription_popup_btn_bg"android:elevation="5dp"android:gravity="center"android:text="立即使用"android:textColor="@color/white"android:textSize="24sp" /></LinearLayout><FrameLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:clipChildren="false"><com.example.picture.MatrixImageViewandroid:id="@+id/iv_matrix"android:layout_width="62dp"android:layout_height="62dp"android:layout_marginTop="20dp"android:layout_marginBottom="30dp" /></FrameLayout>

因为这个会被其他控件遮盖住 所以不能在同一布局下 如果 在他们之上还有其他父布局对于这个父布局一定要加 android:clipChildren=“false”

因为我这边对这个按钮还有其他动画就一并展示出来
按钮定时左右晃动一下

Button bottomBtn = findViewById(R.id.subscription_bottom_btn);
Animation animation1 = shakeAnimation(5);bottomBtn.startAnimation(animation1);animation1.setAnimationListener(new Animation.AnimationListener() {@Overridepublic void onAnimationStart(Animation animation) {}@Overridepublic void onAnimationEnd(Animation animation) {//在这里监听动画消失然后倒计时3秒然后继续动画if (bottomBtn != null && animation1 != null) {bottomBtn.postDelayed(new Runnable() {@Overridepublic void run() {bottomBtn.startAnimation(animation1);}}, 3000);}}@Overridepublic void onAnimationRepeat(Animation animation) {}});public Animation shakeAnimation(int CycleTimes) {Animation translateAnimation = new TranslateAnimation(20, 0, 0, 0);translateAnimation.setInterpolator(new CycleInterpolator(CycleTimes));translateAnimation.setDuration(1500);return translateAnimation;}

获取这个动画的按钮是在页面关闭时做的处理

@Overrideprotected void onDestroy() {super.onDestroy();if (animation != null) {animation.cancel();}if (animation1 != null) {animation1.cancel();}}

大概就是这样了 自己写个demo试一下就行

按钮闪光特效并且定时左右晃动相关推荐

  1. css3.0动画,CSS3.0实现霓虹灯按钮动画特效的示例代码

    今天给大家分享一个用CSS 3.0实现的霓虹灯按钮动画特效,效果如下: 以下是代码实现,欢迎大家复制粘贴和收藏. CSS 3.0实现霓虹灯按钮动画特效 * { font-family: '微软雅黑', ...

  2. web前端项目详解:OPPO首页进度条特效(定时轮播)

    web前端项目详解:OPP首页进度条特效(定时轮播) 知识点:布局结构分析,定位运用,页面兼容性问题,Jquery的基础运用(修改盒子样式,动画方法,简单算法,淡入淡出方法,定时器方法)代码结构 效果 ...

  3. html怎么设置点击播放音乐,html5点击播放音乐试听按钮动画特效

    特效描述:html5 点击播放 音乐试听 按钮动画特效.html5鼠标滑过或点击播放音乐试听特效 代码结构 1. 引入CSS 2. 引入JS 3. HTML代码 Examples eventType ...

  4. jquery仿直播app按钮点赞特效

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. 8种CSS3按钮动画特效【附源码】

    这8款CSS3按钮动画特效.在该特效中,提供了8种按钮动画效果.每种动画在鼠标悬停到按钮上面的时候,都会触发按钮动画. 动画效果截图: 使用方法 HTML结构 最简单的按钮HTML结构如下. < ...

  6. AE489 4K卡通水火焰手绘烟雾漫画泡泡文字闪光特效元素包带Alpha透明通道ae模板

    AE489 4K卡通水火焰手绘烟雾漫画泡泡文字闪光特效元素包带Alpha透明通道ae模板 模板用途:液体,综艺节目动画元素,泡泡文字,卡通,卡通泡泡,文字效果,火,独特,闪光效果,手绘,烟,标题,水 ...

  7. AE片头模板 闪光特效能量爆炸效果logo展示视频模板

    超级闪光特效能量爆炸效果LOGO展示AE视频片头模板 30fps 全高清分辨率 易于编辑 全色彩控制 组织良好 After Effects 2021及更高版本 无需插件 不包括声音

  8. 使用css + 部分js制作按钮流光特效

    制作一个按钮流光特效,其核心就在于规律的动画的执行, 让我们先看看效果吧 鼠标移入会出现颜色循环流动效果. html部分(就是一个简单的a标签) <a href="#"> ...

  9. c++builder按钮设计特效三例

    在程序的使用过程中,使用频率最高的可视化组件可以说就是按钮了.如果在我们设计程序时为按钮增加一些特殊的显示效果,那么一定会为你的应用程序增添不少情趣,下面笔者为大家介绍三种特殊图像按钮显示特效,其运行 ...

最新文章

  1. gitter 卸载_最佳Gitter频道:Scala
  2. PCL中的OpenNI点云获取框架(OpenNI Grabber Framework in PCL)
  3. SharePoint 自定义WebPart之间的连接
  4. Jakarta Commons:巧用类和组件1
  5. 和rna用什么鉴定_RNA-seq:测序原理之文库构建
  6. mysql8.0最低需要多少内存_MySQL8.0内存相关参数介绍
  7. [NewLife.XCode]实体工厂(拦截处理实体操作)
  8. CSS Grid 网格布局教程
  9. 一个简单的状态机设计
  10. 程序员疫苗:代码注入
  11. 【JVM】JVM的生命周期
  12. 重装系统Win10电脑磁盘被写保护怎么办
  13. Oracle和sqlserver数据类型对应
  14. 电脑无线网络显示红叉_Maxidix Wifi Suite下载_无线网络管理软件中文版v14.5.8
  15. python字符串和字节串有什么区别_python中的字符串和字节串
  16. 2sk2225代换3A/1500V中文资料【PDF数据手册】
  17. uc android快捷键,UC手机浏览器助力Android快速上网
  18. Android APP签名和签名等信息查看
  19. 1、基于Keras、Mnist手写数字识别数据集构建全连接(FC)神经网络训练模型
  20. [爬虫架构] 如何在分布式爬虫架构中动态维护一个代理IP池(付费代理)

热门文章

  1. vue重要知识点总结,快来瞅瞅!!
  2. linux程序 在线控制,ToDesk Linux版
  3. 什么是firewalld,简介、策略及规则(Centos7防火墙)
  4. ios银行卡扫描自动识别卡号
  5. 流量卡之家:5G热情不减 5G套餐未推出就拥有了900万用户
  6. 服务器之间传文件夹,文件夹内容为空
  7. 我取名为地图走路法(十面埋伏)
  8. 第八组Postmortem事后分析
  9. systemctl restart network重启网卡失败
  10. 利用css实现黑白版img图片切换