开发者

How do I get the screen width and height when initializing an Android Live Wallpaper?

Trying to code a simple Live wallpaper for android. I'm having trouble finding out h开发者_高级运维ow to capture the screen size at initialization.

Any thoughts on how I might can accomplish this?

Thanks.


onSurfaceChanged provides width and height as part of its parameters. When this method is called during initialization you can grab the values and save them to method variables like mWidth and mHeight. Then you'll have them anywhere, at anytime to use in your code.

Make note that this method is called AFTER onCreate and onSurfaceCreated, so anything that needs width and/or height will have to wait until onSurfaceChanged gets fired.

Check this sample by Google for a clearer picture: http://developer.android.com/resources/samples/CubeLiveWallpaper/src/com/example/android/livecubes/cube1/CubeWallpaper1.html


Does android.util.DisplayMetrics help?

http://developer.android.com/reference/android/util/DisplayMetrics.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜