Organizational Research By

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

15 Answers

0 votes
NULL
answered Sep 30, 2015 by nikhilapatil
0 votes
NULL
answered Sep 30, 2015 by akasati02
0 votes
NULL
answered Sep 30, 2015 by r3tt
0 votes
NULL
answered Sep 30, 2015 by dhananjayksharma
0 votes
NULL
answered Sep 30, 2015 by mannumits1
0 votes
NULL
answered Sep 30, 2015 by sachin valanju
0 votes
NULL
answered Sep 30, 2015 by amit.gupta
0 votes
NULL
answered Sep 30, 2015 by shegokar.anjeet
0 votes
NULL
answered Sep 30, 2015 by deepak gupta
0 votes
NULL
answered Sep 30, 2015 by manju bhargava
0 votes
NULL
answered Sep 30, 2015 by sanjaypal1983
0 votes
NULL
answered Sep 30, 2015 by amit.gupta
0 votes
NULL
answered Sep 30, 2015 by shikhar jain
0 votes
NULL
answered Sep 30, 2015 by patelnikul321
0 votes
NULL
answered Sep 30, 2015 by vimaldas2005

...