我想從屏幕頂部以編程方式在全屏上繪製某些內容。但是,總是有一個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"
這裏是我的了:
它的工作原理。謝謝。 – WeiHung
您現在應該將答案標記爲正確。 –