dialog怎么设置全屏?
1.如果您是直接从资源值转换:intwidth=getResources().getDimensionPixelSize(R.dimen.popup_width);
intheight=getResources().getDimensionPixelSize(R.dimen.popup_height);
getDialog().getWindow().setLayout(width,height);
然后在你的布局中指定match_parent的对话框:android:layout_width="match_parent"
android:layout_height="match_parent"
你只需要担心一个地方。它并不完美,但至少它适用于有一个RelativeLayout作为你的对话框的布局文件的根目录。
2.我有一个固定大小的定义在XML主要布局(LinearLayout中在我的情况)以下内容:
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="1000dp"
android:minHeight="450dp"
3.你可以在下面的代码从Java布局设置宽度和高度。finalAlertDialogalertDialog=alertDialogBuilder.create();
finalWindowManager.LayoutParamsWMLP=alertDialog.getWindow().getAttributes();
WMLP.gravity=Gravity.TOP;
WMLP.y=mActionBarHeight;
WMLP.x=getResources().getDimensionPixelSize(R.dimen.unknown_image_width);
alertDialog.getWindow().setAttributes(WMLP);
alertDialog.show();
4.在我的情况下工作的唯一的事情是该解决方案在这里指出:
从阿迪尔博客文章片段:@Override
publicvoidonStart()
{
super.onStart();
//safetycheck
if(getDialog()==null)
return;
intdialogWidth=...//specifyavaluehere
intdialogHeight=...//specifyavaluehere
getDialog().getWindow().setLayout(dialogWidth,dialogHeight);
//...otherstuffyouwanttodoinyouronStart()method
}
5.我固定它设置根布局intwidth=activity.getResources().getDisplayMetrics().widthPixels;
intheight=activity.getResources().getDisplayMetrics().heightPixels;
content.setLayoutParams(newLinearLayout.LayoutParams(width,height));
Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有