我正在使用警报框,这不适合我的设备屏幕。特别是宽度,我可以通过添加空视图来增加高度,但我无法增加宽度。它在左侧和右侧总是有一些空的空间。
我不确切知道它是android的默认属性还是重新调整大小。我也尝试过自定义提示框,但它对我不起作用。此警报框将更新进度并显示,直到完成进度。
这是我的代码:
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.sync_dialog, null);
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(activity);
alertBuilder.setView(view);
alertBuilder.setCancelable(false);
AlertDialog progress = alertBuilder.create();
// Dialogs set their Window's top level layout width and height to WRAP_CONTENT.
// To make the Dialog bigger, you can set those parameters to FILL_PARENT.
progress.setCanceledOnTouchOutside(false);
progress.setCancelable(false);
progress.getWindow().getAttributes().width = LayoutParams.MATCH_PARENT;
progress.getWindow().getAttributes().height = LayoutParams.MATCH_PARENT;
mProgress = (ProgressBar) view.findViewById(R.id.progress);
/*Dialog dialog = new Dialog(activity, android.R.style.Theme_Translucent_NoTitleBar);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.sync_dialog);
dialog.setCanceledOnTouchOutside(false);
mProgress = (ProgressBar) view.findViewById(R.id.progress);*/
mText = (TextView) view.findViewById(R.id.message);
//Rebuilds ProgressBar with saved state when closed
if (!firstTime) {
mText.setText(mCurrentStatus);
mProgress.setProgress(mProgressStatus);
}
mProgress.setMax(mProgressMax);
return progress;
布局文件是:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/body"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="vertical"
android:paddingBottom="10dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="10dip" >
<ImageView
android:id = "@+id/btn_mfa_home"
android:src="@drawable/ic_mfa_icon_home"
android:layout_width="match_parent"
android:layout_height="fill_parent"
/>
<ImageView
android:id = "@+id/btn_sync_home"
android:src="@drawable/btn_sync_home"
android:paddingTop="50dp"
android:layout_width="match_parent"
android:layout_height="fill_parent"
/>
<TextView
android:id="@+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="12dip"
android:text="@string/dialog_initial_syncing"
android:textColor="@android:color/black" />
<ProgressBar
android:id="@+id/progress"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_gravity="center_horizontal"
android:layout_width="240dip"
android:layout_height="wrap_content"
android:max="100" />
</LinearLayout>
任何建议都将不胜感激!
答案 0 :(得分:0)
你不是setting the attrbutes on the dialog
这样的事情可能会有所帮助
AlertDialog.Builder adb = new AlertDialog.Builder(this);
Dialog d = adb.setView(new View(this)).create();
// (That new View is just there to have something inside the dialog that can grow big enough to cover the whole screen.)
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(d.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.MATCH_PARENT;
d.show();
d.getWindow().setAttributes(lp);
请注意,在显示对话框后设置属性。系统在设置时很挑剔。
答案 1 :(得分:0)
尝试使用LayoutParams
mDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
答案 2 :(得分:0)
我帮助您,请在yourAlertDialog.show()
之后单独使用它 alertDialog.show();
alertDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);