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
精彩评论