Android 自定义对话框中的ImageView-填充父对象不起作用,并且我的对话框很小

Android 自定义对话框中的ImageView-填充父对象不起作用,并且我的对话框很小,android,dialog,imageview,fill-parent,Android,Dialog,Imageview,Fill Parent,我有一个简单的要求:我必须把一些图片(一些小分辨率,一些大分辨率)放在一个对话框中并全屏显示 我试过这个: Dialog dialog = new Dialog(getActivity()); dialog.setContentView(R.layout.custom_dialog); int picId = Integer.valueOf(webcamCursor.getString(webcamCursor .getColumnIndex("_id"))); dialog.s

我有一个简单的要求:我必须把一些图片(一些小分辨率,一些大分辨率)放在一个对话框中并全屏显示

我试过这个:

Dialog dialog = new Dialog(getActivity());
dialog.setContentView(R.layout.custom_dialog);
int picId = Integer.valueOf(webcamCursor.getString(webcamCursor
        .getColumnIndex("_id")));
dialog.setTitle(webcamCursor.getString(webcamCursor
        .getColumnIndex("City")));
image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.icon);            
new DownloadPicTask().execute(Snippets.getUrlFromCat(picId, cat));
dialog.show();
我的布局是:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/layout_root"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:layout_gravity="center"
              >
    <ImageView android:id="@+id/image"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:padding="10dip"
               />
</LinearLayout>

正如我写的“到处填充家长”一样,这个对话框不应该是全屏的吗

试试看:

dialog.getWindow().getAttributes().width = LayoutParams.FILL_PARENT;
希望能有帮助

try this will work

//Grab the window of the dialog, and change the width
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
        Window window = dialog.getWindow();
        lp.copyFrom(window.getAttributes());
        //This makes the dialog take up the full width
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(lp);