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

编程入门 行业动态 更新时间:2024-10-27 10:31:21

android 高仿遇爱,高仿Android今日<a href=https://www.elefans.com/category/jswz/34/1765373.html style=头条(微头条)点赞动画"/>

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

预览

img

思路

img

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

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

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

代码

本来打算自己写,后来发现有一个不错的动画效果库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

更多推荐

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

本文发布于:2024-03-07 11:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1717718.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:头条   今日   动画   android   高仿遇爱

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!