1

Trying to code a simple Live wallpaper for android. I'm having trouble finding out how to capture the screen size at initialization.

Any thoughts on how I might can accomplish this?

Thanks.

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
max
  • 2,346
  • 4
  • 26
  • 34

2 Answers2

7

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

Shomari
  • 405
  • 4
  • 12
1

Does android.util.DisplayMetrics help?

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

Squonk
  • 48,735
  • 19
  • 103
  • 135