Fork me on GitHub

DialogFragment的宽高设置

方法一

1
2
3
4
5
6
7
8
9
@Override
public void onResume() {
ViewGroup.LayoutParams params = getDialog().getWindow().getAttributes();
params.width = LayoutParams.MATCH_PARENT;
params.height = LayoutParams.MATCH_PARENT;
getDialog().getWindow().setAttributes((android.view.WindowManager.LayoutParams) params);

super.onResume();
}

方法二

1
2
3
4
5
@Override
public void onResume() {
getDialog().getWindow().setLayout(width, height);
super.onResume();
}