Friday, December 31, 2010

[android-developers] using getSurfaceFrame to get display width/height?

So I'm trying out making a live wallpaper and I'm using the sample
code provided in the SDK for the cube live wallpaper

I wanted to use this code to get the height/width of the display


@Override
public void onCreate(SurfaceHolder surfaceHolder) {
super.onCreate(surfaceHolder);

Rect frame = getSurfaceHolder().getSurfaceFrame();
float width = frame.width();
float height = frame.height();
// By default, we don't get touch events, so enable them.
setTouchEventsEnabled(true);
}

Unfortunately, when I run this code, the width and height return as 0,
though if I put this in onVisibilityChanged, the correct values are
returned, why is this and is it suitable to move the code to
onVisibilityChanged?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate