Android - Bias Lock Live Wallpaper

I am writing live wallpapers for Android. To check my base code, I drew a rectangle in the upper left corner of the screen:

canvas.drawRect(0f,0f,50f,50f,paint); 

Half of the rectangle was under the line at the top of the main screen. alt text

I tried to account for pixel offsets using:

 public void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) ... canvas.drawRect(0f+xPixelOffset,0f+yPixelOffset,50f+xPixelOffset,50f+yPixelOffset ,paint); 

But the rectangle is still drawn under the panel. How to find where the bar ends so I can draw below it?

Greetings

Pete

+6
android offset wallpaper draw live-wallpaper
source share
2 answers

This SO answer seems to provide a way to get the status bar height : Status bar height? I copied the code below - originally answered by Jorgesys .

 Rect rectgle= new Rect(); Window window= getWindow(); window.getDecorView().getWindowVisibleDisplayFrame(rectgle); int StatusBarHeight= rectgle.top; int contentViewTop= window.findViewById(Window.ID_ANDROID_CONTENT).getTop(); int TitleBarHeight= contentViewTop - StatusBarHeight; Log.i("*** Jorgesys :: ", "StatusBar Height= " + StatusBarHeight + " , TitleBar Height = " + TitleBarHeight); 

Hope this helps.

+9
source share

Have you checked if the bias is set (suppose your bias variables are zero)? I would also draw under the bar because there are some home screen applications that can mix the bar and you will have an empty area.

I also assume that the offset you are using is only used if you switch to other screens ...

+3
source share

All Articles