Android动态壁纸的性能和省电做法?

发布于 2024-11-18 10:19:48 字数 150 浏览 3 评论 0原文

很容易找到很多讨论初学者实现动态壁纸的文章,其中解决了涉及表面等的主要问题。

但动态壁纸的专业发展又如何呢?以正确的方式构建代码以确保良好的性能、低功耗(以节省电池电量)并最适合不同设备的最佳实践是什么?

如果可能的话,一些涵盖这些问题的代码示例会很棒。

It's easy to find many articles discussing the implementation of Live Wallpapers for beginners, which addresses major questions involving Surfaces and so on.

But what about the professional development of Live Wallpapers? What are best practices for structuring the code the right way, to ensure good performance, low power consumption (to save battery power) and best fit different devices?

If possible, some code samples covering these issues would be great.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

始终不够 2024-11-25 10:19:48

功耗...
1)到目前为止,最重要的是你的壁纸应该在不可见时自动关闭。立方体示例正确处理了这个问题,删除了 onDestroy()、onSurfaceDestroyed() 和 onVisibilityChanged() 中的可运行回调(当visible == false时)。
2) 除此之外,功耗的最大决定因素是帧速率。 24 fps 的动画比仅以 1 fps 更新以使其扫秒针滴答作响的时钟消耗更多的能量。没有办法解决这个问题,除非教育用户,使期望合理。无论是应用程序还是动态壁纸,动作游戏都会耗尽您的电池。

性能...
在画布上绘图的优点是简单,但对于非常复杂的壁纸,您将需要使用 OpenGL。有 GLWallpaperService 和 AndEngine。库存壁纸被配置为使用 RenderScript(您可能会发现在 Android 源代码树中查找此代码很有用 - 比 SDK 中的立方体示例复杂得多)。还有一些关于扩展 libGDX 来处理壁纸的讨论。

最适合...
嗯,它就像 Android 的其他部分一样:您需要根据可缩放比例设计您的作品,查询设备并进行相应调整。对于简单的壁纸,通常足以在 onSurfaceChanged() 中缩放您的图稿,其中您将获得宽度和高度作为参数。在某些情况下,您可能想要检查完整的 DisplayMetrics。

Power consumption...
1) The most important thing, by far, is that your wallpaper should switch itself off when it is not visible. The cube example handles this correctly, removing runnable callbacks in onDestroy(), onSurfaceDestroyed(), and onVisibilityChanged() (when visible == false).
2) Beyond that, the largest determinant of power drain will be your frame rate. A 24 fps animation will drain much more juice than a clock that just updates at 1 fps to make its sweep-second hand tick. There's no way around this, except to educate the user, so that expectations are reasonable. An action game will kill your battery whether it's an app or a live wallpaper.

Performance...
Drawing to a canvas has the benefit of simplicity, but for a very sophisticated wallpaper you will need to use OpenGL. There's GLWallpaperService, and AndEngine. The stock wallpapers are rigged to use RenderScript (you may find it useful to look up this code within the Android source tree -- much more sophisticated than the cube example in the SDK). And there was some talk about extending libGDX to handle wallpaper.

Best Fit...
Well, it's just like the rest of Android: you need to design your artwork in terms of scalable proportions, query the device, and adjust accordingly. For a simple wallpaper, it's usually enough to scale your artwork in onSurfaceChanged(), where you are given the width and the height as parameters. In some cases you may want to examine the full DisplayMetrics.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文