ImageView в пользовательском диалоге - fill_parent не работает, и мой диалог маленький

У меня есть простая просьба: я должен поместить несколько изображений (небольшое разрешение, большое разрешение) в диалог и отобразить их в полноэкранном режиме.

Я попробовал это:

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 ответа

Решение

Попробуй это:

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);
Другие вопросы по тегам