Android - 动态壁纸偏移剪辑

时间:2010-08-18 15:39:41

标签: android draw offset live-wallpaper wallpaper

我正在为Android编写动态壁纸。为了测试我的基本代码是否正常工作,我在屏幕的左上角显示了一个矩形:

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

矩形的一半位于主屏幕顶部的栏下方。alt text

我尝试使用以下方法考虑像素偏移:

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);

但矩形仍然在条形图下方绘制。怎么找到栏的结束所以我可以在它下面画?

干杯,

皮特

2 个答案:

答案 0 :(得分:9)

这个SO答案似乎提供了一种获取状态栏高度的方法:Height of statusbar? 我复制了以下代码 - 最初由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); 

希望它有所帮助。

答案 1 :(得分:3)

您是否检查过是否设置了偏移量(猜测偏移量变量是否为零)? 我也会在条形图下画画,因为有一些主屏幕应用程序可以混合使用条形图,而不是一个空白区域。

我还猜测你使用的偏移仅在你滑到其他屏幕时使用......