2015-09-26 90 views
1

我想從屏幕頂部以編程方式在全屏上繪製某些內容。但是,總是有一個y軸偏移量。它似乎是身份(標題)欄的高度。Android WindowManager.LayoutParams y偏移量

這裏是我的代碼:

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_main); 
    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
      WindowManager.LayoutParams.WRAP_CONTENT, 
      WindowManager.LayoutParams.WRAP_CONTENT, 
      WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, 
      WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE 
        | WindowManager.LayoutParams.FLAG_FULLSCREEN, 
      PixelFormat.TRANSLUCENT); 
    params.gravity = Gravity.LEFT | Gravity.TOP; 
    params.x = 0; 
    params.y = 0; 
    params.width = 200; 
    params.height = 300; 

    GradientDrawable gd = new GradientDrawable(); 
    gd.setShape(GradientDrawable.RECTANGLE); 
    gd.setColor(Settings.highlightColor); 
    ImageView iv = new ImageView(this); 
    iv.setImageDrawable(gd); 
    WindowManager windowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE); 
    windowManager.addView(iv, params); 

我已經設置全屏在AndroidManifest.xml:

android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" 

這裏是我的了:

Result

回答

1

使用此:

WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN; 
+0

它的工作原理。謝謝。 – WeiHung

+0

您現在應該將答案標記爲正確。 –

0

嘗試增加FLAG_TRANSLUCENT_STATUS到您的LayoutParams

paramsFlags |= WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS; 
+0

試過,但沒有運氣。 – WeiHung

相關問題