Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


android how to stretch an image to the screen width while maintaining aspect ra


android how to stretch an image to the screen width while maintaining aspect ra  using -'java,android,layout'

I want to download an image (of unknown size, but which is always roughly square) and display it so that it fills the screen horizontally, and stretches vertically to maintain the aspect ratio of the image, on any screen size. Here is my (non-working) code. It stretches the image horizontally, but not vertically, so it is squashed...

ImageView mainImageView = new ImageView(context);
    mainImageView.setImageBitmap(mainImage); //downloaded from server
    mainImageView.setScaleType(ScaleType.FIT_XY);
    //mainImageView.setAdjustViewBounds(true);
    //with this line enabled, just scales image down
    addView(mainImageView,new LinearLayout.LayoutParams(
            LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

    

asked Sep 30, 2015 by gauravg.gwl
0 votes
14 views



Related Hot Questions



Government Jobs Opening


...