WindowManager.LayoutParams params = getWindow().getAttributes();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
params.gravity = Gravity.BOTTOM;
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
TypedArray a = obtainStyledAttributes(new int[]{android.R.attr.layout_width});
try {
params.width = a.getLayoutDimension(0, ViewGroup.LayoutParams.MATCH_PARENT);
} finally {
a.recycle();
}
}
getWindow().setAttributes(params);
- 注意事项: setContentView() 先于上述代码 调用。