自定义对话框中的ImageView——fill_parent不起作用,我的对话框很小

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,那么对话框不应该占据整个屏幕吗?

图片描述

2个回答

8

请尝试以下方法:

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

希望能对你有所帮助。

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);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接