Search code examples
androiddialogimageviewfill-parent

ImageView in a Custom Dialog - fill_parent does not work and my dialog is small


I have a simple request: I have to put some pictures (some small resolution, some big resolution) in a dialog and display them fullscreen.

I tried this:

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

And my layout is:

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

As I wrote fill_parent everywhere, shouldn't the dialog take the full screen?

enter image description here


Solution

  • Try that:

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

    Hope it helps.