1. 程式人生 > >Android今日頭條(微頭條)點贊動畫

Android今日頭條(微頭條)點贊動畫

前言

設計很開心,又找到一個好看的效果。
開發很痛苦,又要百度找效果。納尼!!!沒找到!!! o(TωT)o
設計直接把原效果給我看,讓我抄…

預覽

img

APK下載

思路

img

  1. 小紅框是點讚的圖示,帶有一點動畫。大紅框是表情噴射的區間,並且是從小紅框中間的位置開始噴射。就註定兩個view不是一體的。
  2. 將噴射區域自定為一個遮罩層,通過getLocationOnScreen(int[] outLocation)獲取點贊view的位置,並從當前位置開始噴射。
  3. 噴射的數量、速度、角度、方向是隨機的,也可以有一些旋轉和縮放的動畫,還可以設定噴射的角度控制方向。

程式碼

本來打算自己寫,後來發現有一個不錯的動畫效果庫

Leonids,先看看它的效果:

img

如果能實現多張圖片就是咱們想要的效果了,然後開始擴充套件方法。

 public ParticleSystem(ViewGroup parentView, Resources resources, int maxParticles, int[] drawableInts, long timeToLive) {
        this(parentView, maxParticles, timeToLive);
        if (drawableInts != null && drawableInts.length > 0) {
            for
(int i = 0; i < mMaxParticles; i++) { Drawable drawable = resources.getDrawable(drawableInts[i % drawableInts.length]); if (drawable instanceof AnimationDrawable) { AnimationDrawable animation = (AnimationDrawable) drawable; mParticles.add(new
AnimatedParticle(animation)); } else { Bitmap bitmap; if (drawable instanceof BitmapDrawable) { bitmap = ((BitmapDrawable) drawable).getBitmap(); } else { bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); drawable.draw(canvas); } mParticles.add(new Particle(bitmap)); } } } }

實現動畫的程式碼:

 ParticleSystem ps = new ParticleSystem((Activity) getContext(), 100, iconInts, jetDuration);
 ps.setScaleRange(0.7f, 1.3f);
 ps.setSpeedModuleAndAngleRange(0.1f, 0.5f, 180, 360);
 ps.setAcceleration(0.0001f, 90);
 ps.setRotationSpeedRange(90, 180);
 ps.setFadeOut(200, new AccelerateInterpolator());
 ps.oneShot(this, 10, new DecelerateInterpolator());

通過這個庫實現的好處:因為這個庫比較好,本身動畫就很流暢。相對於自己實現效果流暢太多了。SuperLike這是一個大神自己實現的,可以參考一下,也可以對比一下效果。

Github