我在我的活动代码(不是xml)中创建了系统范围的全屏叠加布局。问题是布局不占据屏幕的整个高度。顶部和底部有间隙。知道如何使布局适合整个屏幕高度吗?
mFrameLayout = new FrameLayout(this);
mFrameLayout.setBackgroundColor(getResources().getColor(R.color.black));
mFrameLayout.getBackground().setAlpha(50);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT
);
WindowManager windowManager = (WindowManager) getApplicationContext().getSystemService(WINDOW_SERVICE);
windowManager.addView(mFrameLayout, params);
答案 0 :(得分:0)
简单地改变' FLAG_FULLSCREEN'到' MATCH_PARENT'。
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);
或者从视图中删除系统ui(Status& Nav Bar):
int KitKatFlags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LOW_PROFILE
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
getWindow().getDecorView().setSystemUiVisibility(KitKatFlags);