0

Possible Duplicate:
Android: Scale a Drawable or background image?

I'd like to make a popup that contains an ImageView. Right now, the Drawable that I'm showing is 100x200px big. The Drawable is of good quality, so I would like to show the image fullscreen. I have no idea how though. This is my code so far:

        AlertDialog.Builder imgDialog = new AlertDialog.Builder(
            myactivity.this);
    ImageView imageView = new ImageView(myactivity.this);

    Matrix matrix = new Matrix();
    matrix.postScale(2, 2);

    imageView.setImageDrawable(myDrawable);
    imageView.setImageMatrix(matrix);



    LayoutParams imageViewLayoutParams = new LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    imageView.setLayoutParams(imageViewLayoutParams);

    LinearLayout layout = new LinearLayout(myactivity.this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(imageView);

    imgDialog.setView(layout);

I already tried to set the WRAP_CONTENT of the ImageView LayoutParams on FILL_PARENT, but this doesn't change the situation. The Drawable width is 100, and the height is 200. I'm thinking about scaling the Drawable or the ImageView, but failed to get this done so far..

Any help would be appreciated!

Community
  • 1
  • 1
harmjanr
  • 930
  • 2
  • 11
  • 27
  • This appears to be a [duplicate question](http://stackoverflow.com/q/1400782/403455). – Jeff Axelrod Dec 22 '11 at 18:42
  • Thanks, didn't find this one after searching on Google. The width is stretched now, but the height is still the original size.. Any idea why? – harmjanr Dec 22 '11 at 19:20

1 Answers1

1

Try manipulating the window object of the dialog.

Dialog dialog = imgDialog.create();
dialog.setContentView(layout);
Window window = dialog.getWindow();
window.setLayout(
    (int)(window.getWindowManager().getDefaultDisplay().getWidth()),
    (int)(window.getWindowManager().getDefaultDisplay().getHeight() ));

This will force the dialog to take 100% of the screen in both directions.

riotopsys
  • 564
  • 4
  • 7