android 高仿遇爱,高仿Android今日头条(微头条)点赞动画

预览

fb81b23acff7

img

思路

fb81b23acff7

img

小红框是点赞的图标,带有一点动画。大红框是表情喷射的区间,并且是从小红框中间的位置开始喷射。就注定两个view不是一体的。

将喷射区域自定为一个遮罩层,通过getLocationOnScreen(int[] outLocation)获取点赞view的位置,并从当前位置开始喷射。

喷射的数量、速度、角度、方向是随机的,也可以有一些旋转和缩放的动画,还可以设定喷射的角度控制方向。

代码

本来打算自己写,后来发现有一个不错的动画效果库Leonids,先看看它的效果:

fb81b23acff7

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值