3

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

我试过这个:

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>

当我到处写fill_parent时,对话框不应该全屏吗?

在此处输入图像描述

4

2 回答 2

8

试试看:

dialog.getWindow().getAttributes().width = LayoutParams.FILL_PARENT;

希望能帮助到你。

于 2012-01-12T09:18:20.067 回答
0
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);
于 2014-08-19T10:38:40.093 回答