美文网首页
模仿微博点赞动画

模仿微博点赞动画

作者: tenny_wu | 来源:发表于2017-11-20 16:02 被阅读752次

在刷微博的时候,发现微博最近版本更新了一个点赞的动画,最近项目不是太忙,就模仿实现一下。

效果图:

gif看起来卡顿,不流畅,真机运行起来效果会好很多

ezgif-1-fdcd65cd45.gif
动画思路:

1、大拇指的旋转、位移、缩放变换

2、背景圆圈

3、烟花效果

先看一下布局
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <com.tenny.BgView
        android:id="@+id/bg"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"/>
    <com.tenny.FireworkView
        android:id="@+id/fireworks"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:visibility="invisible"/>
    <com.tenny.CircleView
        android:id="@+id/circle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"/>
    <ImageView
        android:id="@+id/icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="40dp"
        />
</merge>
大拇指动画

点赞过程中,大拇指的上顶、抖动效果,用属性动画的位移、缩放、旋转实现。这个大拇指的图片我用了矢量图,这里有一个在线转换SVG网址:https://www.vectorizer.io/

   ObjectAnimator starScaleYAnimator = ObjectAnimator.ofFloat(icon, ImageView.SCALE_Y, 1.0f, 2f, 1.0f);
   starScaleYAnimator.setDuration(500);

   ObjectAnimator starScaleXAnimator = ObjectAnimator.ofFloat(icon, ImageView.SCALE_X, 1.0f, 2f, 1.0f);
   starScaleXAnimator.setDuration(500);

   ObjectAnimator translationYAnimator = ObjectAnimator.ofFloat(icon, "translationY", 0, -20, 0);
   translationYAnimator.setDuration(500);

   ObjectAnimator rotateAnimator = ObjectAnimator.ofFloat(icon, "rotation", 0, 10, 0, -10, 0);
   rotateAnimator.setDuration(500);
背景圆圈动画

背景圆圈很简单,就是用PorterDuff.Mode.CLEAR模式画了一个同心圆。然后用Property<T, V>包装一个属性,进行属性动画

  @Override
  protected void onDraw(Canvas canvas) {
       super.onDraw(canvas);
       tempCanvas.drawColor(0xffffff, PorterDuff.Mode.CLEAR);
       tempCanvas.drawCircle(getWidth() / 2, getHeight() / 2, circleRadiusProgress * maxCircleSize, circlePaint);
       tempCanvas.drawCircle(getWidth() / 2, getHeight() / 2, circleRadiusProgress * maxCircleSize/3, maskPaint);
       canvas.drawBitmap(tempBitmap, 0, 0, null);
    }

  public static final Property<CircleView, Float> CIRCLE_RADIUS_PROGRESS =
       new Property<CircleView, Float>(Float.class, "circleRadiusProgress") {
              @Override
              public Float get(CircleView object) {
                  return object.getCircleRadiusProgress();
              }

              @Override
              public void set(CircleView object, Float value) {
                  object.setCircleRadiusProgress(value);
              }
        };
 ObjectAnimator roundAnimator = ObjectAnimator.ofFloat(circleView,CircleView.CIRCLE_RADIUS_PROGRESS, 0f, 1f);
 roundAnimator.setDuration(250);
 //等大拇指变到最大,顶到最高,开始背景圆圈动画
 rotateAnimator.setStartDelay(250);
烟花动画

烟花效果,以270为中心画五条线,进行长短变换。也是一样,用Property<T, V>包装一个属性,进行属性动画

  private static final int LINES_COUNT = 5;
  //每条线的间隔角度
  private static final int LINES_POSITION_ANGLE = 51;

  //给0.1的起始长度
  private void updateLinesPosition() {
       this.startRadius = (0.2f + 0.8f * currentProgress) * maxFireworkRadius;
       this.endRadius = (0.3f + 0.7f * currentProgress) * maxFireworkRadius;
  }

   @Override
   protected void onDraw(Canvas canvas) {
        for (int i = 0; i < LINES_COUNT; i++) {
            int start_X = (int) (centerX + startRadius * Math.cos(((2-i) * LINES_POSITION_ANGLE + 270) * Math.PI / 180));
            int start_Y = (int) (centerY + startRadius * Math.sin(((2-i) * LINES_POSITION_ANGLE + 270) * Math.PI / 180));
            int end_X = (int) (centerX + endRadius * Math.cos(((2-i) * LINES_POSITION_ANGLE + 270) * Math.PI / 180));
            int end_Y = (int) (centerY + endRadius * Math.sin(((2-i) * LINES_POSITION_ANGLE + 270) * Math.PI / 180));
            canvas.drawLine(start_X, start_Y, end_X, end_Y, fireworkPaint);
        }
   }

   public static final Property<FireworkView, Float> FIREWORK_PROGRESS = new Property<FireworkView, Float>(Float.class, "fireworkProgress") {
        @Override
        public Float get(FireworkView object) {
            return object.getCurrentProgress();
        }

        @Override
        public void set(FireworkView object, Float value) {
            object.setCurrentProgress(value);
        }
    };
   ObjectAnimator fireworkAnimator = ObjectAnimator.ofFloat(firewokView, FireworkView.FIREWORK_PROGRESS, 0, 1f);
   fireworkAnimator.setDuration(250);
   //等大拇指变到最大,顶到最高,开始烟花动画
   rotateAnimator.setStartDelay(250);
完整源码:

完整源码在GitHub
喜欢的话,记得star哦!

相关文章

  • 模仿微博点赞动画

    在刷微博的时候,发现微博最近版本更新了一个点赞的动画,最近项目不是太忙,就模仿实现一下。 效果图: gif看起来卡...

  • ios 点赞动画

    模仿的qq空间的点赞。qq的是从未点赞状态到点赞是有动画。从点赞状态到未点赞是没有动画。 写的butten的分类。...

  • 微博真人点赞渠道,微博买真人赞平台,微博买点赞平台,

    微博点赞在线下单,微博真人点赞购买微信youtui2 10个赞微博真人粉丝自助下单,微博真人赞网站,微博刷点赞,刷...

  • 模仿新浪微博

    DSLolita lolita objective-c 版本 模仿新浪微博做的一款app,有发送博文,评论,点赞,...

  • 点赞动效:缩放和抖动结合

    先上示例图:点赞动画.gif 直接上代码: 点赞动效 取消点赞动效 微博的点赞效果很是给力,最近有需求让实现那种效...

  • iOS 抖音点赞动画 收藏动画

    JWGiveLikeAnimation 描述:iOS 抖音点赞动画 收藏动画git传送门 前言 最近项目中需要模仿...

  • 解决因UINavigationControllerDelegat

    背景 项目需要,为了实现类似于微博点赞的效果: 在微博详情中,点赞后,返回微博列表,刷新刚刚点赞的微博。 简单来说...

  • 微博点赞彩蛋

    今天刷微博的时候,对某博主发表的内容点赞,发现改版了,改版如下: ①在微博当前页点赞,就会在内容的中间这个地方出现...

  • 为微博点赞

    刚刚看到一个消息,很开心。 上图 为何开心? 就如图中,微博官方说明的 “部分账号” 【刻意激化矛盾】 【刻意进行...

  • iOS动画实现微博点赞按钮选中效果

    简单实现微博点赞按钮效果,比较简单的放大缩小使用,直接上代码

网友评论

      本文标题:模仿微博点赞动画

      本文链接:https://www.haomeiwen.com/subject/gsimvxtx.html