Android的动态壁纸动画 [英] Android Live Wallpaper Animation

查看:269
本文介绍了Android的动态壁纸动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是显示动画作为动态壁纸的最佳方式?现在我有一个GIF拆分成11 png格式(每帧),然后我就在做

What's the best way to display an animation as a live wallpaper? Right now I have a gif split into 11 pngs (one per frame) and then I just am doing

public Bitmap frame0;
ArrayList<Bitmap> frameArray = new ArrayList<Bitmap>();
frame0 = BitmapFactory.decodeResource(getResources(), R.drawable.nyancat0);
frame0 = Bitmap.createScaledBitmap(frame0, minWidth, minHeight, true);
frameArray.add(frame0);

然后我通过框架使用for循环中循环,并吸引他们在画布上

Then I just use a For Loop to loop through the frames and draw them on a canvas

canvas.drawBitmap(frameArray.get(indexnumber), 0, 0, mPaint);

然后我就改变我的indexnumber ++,除非它是11,那么我回去1。
这样的作品,但当然,存储许多位图是非常低效的内存。这阻止了我这样做多层或其他很酷的效果,而不滞后和电池消耗。有没有更好的方式来显示对Android动态壁纸的动画?我想电影的显示整个GIF但是这不支持动态壁纸。

and then I just change my indexnumber++ unless it's 11, then I go back to 1. That works, but of course, storing that many Bitmaps is very memory inefficient. This stops me from doing multiple layers or other cool effects without lagging and battery drain. Is there a better way to display an animation on the Android Live wallpaper? I tried Movie for displaying the whole GIF but that's not supported for live wallpapers.

推荐答案

确实图片加载需要多长时间?如果它是可以忽略不计,那么你显示它之前,为什么不加载正确的每个图像,丢弃旧的?这样,你只需要在任何一个阶段,在内存中1的图像。

How long does the loading of images take? If it's negligible then why not load each image in right before you display it, discarding the old one? That way you only have 1 image in memory at any one stage.

另外做一些类似于使用后缓冲区,在内存中两个空间,一个是现在的图像显示,你加载下一个图像的另一成。当它的时间来改变你作出新加载的位图可见,卸载等,然后下一帧加载到这一点。

Alternatively do something akin to using a back buffer, have two spaces in memory, one for the image being displayed now, an another into which you're loading the next image. When it's time to change you make the newly loaded bitmap visible, unload the other and then load the next frame into that.

这篇关于Android的动态壁纸动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆