Android高级UI特效仿直播点赞动画效果

发布时间:2020-10-02 16:06:18 作者:mrr
来源:脚本之家 阅读:374

本文给大家分享高级UI特效仿直播点赞效果—一个优美炫酷的点赞动画,具体实现代码大家参考本文。

效果图如下:

Android高级UI特效仿直播点赞动画效果

Android高级UI特效仿直播点赞动画效果

攻克难点:

心形图片的路径等走向 心形图片的控制范围

部分代码如下:

通过AbstractPathAnimator定义飘心动画控制器

@Override
 public void start(final View child, final ViewGroup parent) {
 parent.addView(child, new ViewGroup.LayoutParams(mConfig.heartWidth, mConfig.heartHeight));
 FloatAnimation anim = new FloatAnimation(createPath(mCounter, parent, 2), randomRotation(), parent, child);
 anim.setDuration(mConfig.animDuration);
 anim.setInterpolator(new LinearInterpolator());//启动动画
 anim.setAnimationListener(new Animation.AnimationListener() {
  @Override
  public void onAnimationEnd(Animation animation) {
  mHandler.post(new Runnable() {
   @Override
   public void run() {
   parent.removeView(child);
   }
  });
  mCounter.decrementAndGet();
  }
  @Override
  public void onAnimationRepeat(Animation animation) {
  }
  @Override
  public void onAnimationStart(Animation animation) {
  mCounter.incrementAndGet();
  }
 });
 anim.setInterpolator(new LinearInterpolator());
 child.startAnimation(anim);
 }

/**
 * 根据图片设置bitmap
 * @param color
 * @return
 */
 public Bitmap createHeart(int color) {
 if (sHeart == null) {
  sHeart = BitmapFactory.decodeResource(getResources(), mHeartResId);
 }
 if (sHeartBorder == null) {
  sHeartBorder = BitmapFactory.decodeResource(getResources(), mHeartBorderResId);
 }
 Bitmap heart = sHeart;
 Bitmap heartBorder = sHeartBorder;
 Bitmap bm = createBitmapSafely(heartBorder.getWidth(), heartBorder.getHeight());
 if (bm == null) {
  return null;
 }
 Canvas canvas = sCanvas;
 canvas.setBitmap(bm);
 Paint p = sPaint;
 canvas.drawBitmap(heartBorder, 0, 0, p);
 p.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
 float dx = (heartBorder.getWidth() - heart.getWidth()) / 2f;
 float dy = (heartBorder.getHeight() - heart.getHeight()) / 2f;
 canvas.drawBitmap(heart, dx, dy, p);
 p.setColorFilter(null);
 canvas.setBitmap(null);
 return bm;
 }

如何创建一个path

public Path createPath(AtomicInteger counter, View view, int factor) {
 Random r = mRandom;
 int x = r.nextInt(mConfig.xRand);
 int x2 = r.nextInt(mConfig.xRand);
 int y = view.getHeight() - mConfig.initY;
 int y2 = counter.intValue() * 15 + mConfig.animLength * factor + r.nextInt(mConfig.animLengthRand);
 factor = y2 / mConfig.bezierFactor;
 //随机xPoint
 int xPointFactor = mRandom.nextInt(mConfig.xPointFactor);
 x = xPointFactor + x;
 x2 = xPointFactor + x2;
 int y3 = y - y2;
 y2 = y - y2 / 2;
 Path p = new Path();
 p.moveTo(mConfig.initX, y);
 p.cubicTo(mConfig.initX, y - factor, x, y2 + factor, x, y2);
 p.moveTo(x, y2);
 p.cubicTo(x, y2 - factor, x2, y3 + factor, x2, y3);
 return p;
 }

Activity中代码:

Android高级UI特效仿直播点赞动画效果

Android高级UI特效仿直播点赞动画效果

Android高级UI特效仿直播点赞动画效果

下面给大家分享一个源码:html5+canvas仿抖音直播爱心飘动点赞动画特效源码

总结

以上所述是小编给大家介绍的Android高级UI特效仿直播点赞动画效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对亿速云网站的支持!

推荐阅读:
  1. 微信小程序中如何基于Canvas实现直播点赞气泡效果
  2. Android控件FlowLikeView实现点赞动画

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

android 直播 点赞

上一篇:Flutter定时器、倒计时的快速上手及实战讲解

下一篇:extract-text-webpack-plugin用法详解

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》