简体   繁体   English

Android LIVE壁纸方法?

[英]Android LIVE Wallpaper approach?

I'm entirely new to Android development, and I'm interested in making a live wallpaper. 我是Android开发的新手,我对制作动态壁纸很感兴趣。 I was thinking about looping a set of pictures instead of drawing the animation. 我在考虑循环一组图片而不是绘制动画。 Is this a possible approach? 这是一种可行的方法吗? If possible is this a suitable or ideal way of doing it, does it eat up memory and would i need images with different resolutions because of the fragmentation?(hundreds of different devices) 如果可能的话,这是一个合适的或理想的方式,它是否会占用内存,我是否需要具有不同分辨率的图像,因为碎片?(数百种不同的设备)

Thanks in advance :) 提前致谢 :)

Sure, it should be fairly simple. 当然,它应该相当简单。

The main part of the Wallpaper engine is the Drawing of course. Wallpaper引擎的主要部分是Drawing当然。 You need to handle the drawing manually, there is no easy way to loop through images... you need to code it. 您需要手动处理绘图,没有简单的方法来循环图像...您需要对其进行编码。 You will have to continuously monitor the time which has passed and adjust the displayed image based on that. 您必须持续监控已经过的时间并根据该时间调整显示的图像。 You are given a Canvas object to draw to and it is all done during run-time in code. 您将获得一个Canvas对象以进行绘制,并且它在代码中的运行时完成。

The Wallpaper engine class has a event called onSurfaceChanged which gives you the width and height of the Surface which you will be drawing to. Wallpaper引擎类有一个名为onSurfaceChanged的事件,它为您提供要绘制的Surface的宽度和高度。 It will be called everytime the screen dimensions change (like if the phone is put into Landscape mode for instance). 每次屏幕尺寸改变时都会调用它(例如,如果手机进入横向模式)。 You need to have code that will handle any combination of width or height for all the device types out there. 您需要拥有能够处理所有设备类型的任何宽度或高度组合的代码。 You will need to decide if you are going to stretch, center, tile or crop (Or a combination of those) the source images to fit any particular screen size. 您需要决定是否要拉伸,居中,平铺或裁剪(或其组合)源图像以适合任何特定的屏幕尺寸。 I would recommend scale to fit so that the image is either taller or wider than the screen and center the image either vertically or horizontally (cropping the extra bits) once that is done. 我建议缩放比例以使图像比屏幕更高或更宽,并在完成后垂直或水平(裁剪额外的位)使图像居中。 I personally just use one source size and resize it to fit. 我个人只使用一个源大小并调整大小以适应。 You can opt to use several source files if you want which is the recommended approach I believe, but it's a little confusing. 你可以选择使用几个源文件,如果你想要的是我认为的推荐方法,但它有点令人困惑。

I would start by creating a Live Wallpaper which just draws something basic like a shape to the screen. 我首先要创建一个动态壁纸,它只是在屏幕上绘制一些基本的形状。 Then work out how to display an custom image and take it from there. 然后找出如何显示自定义图像并从那里获取它。

Good luck 祝好运

You will need to be very careful about memory if taking a frame approach to animation--probably will not be possible to animate full frames--much more practical to move sprites on a background. 你需要非常小心内存,如果采取帧方式动画-可能将无法进行动画全帧-更实际的背景上移动精灵。 See, fr'instance: http://davidjhinson.wordpress.com/2010/05/19/scarce-commodities-google-android-memory-and-bitmaps/ 见,fr'instance: http ://davidjhinson.wordpress.com/2010/05/19/scarce-commodities-google-android-memory-and-bitmaps/

如果你有一个png帧动画设置在某个位于背景图像上的某个位置的x和y位置,那么两者都必须重新调整

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM