How to avoid the streching of Images in Android -


i trying put images programmatically .but when putting images getting stretched .i using micromax canvas view application .

this code

void populatedata(){         populate=(linearlayout)findviewbyid(r.id.populate);         linearlayout.layoutparams params = new linearlayout.layoutparams(                 layoutparams.wrap_content, layoutparams.wrap_content);         params.weight=1.0f;          for(int i=0;i<10;i++) {             linearlayout hr_populate=new linearlayout(this);             hr_populate.setorientation(linearlayout.horizontal);              imageview img=new imageview(this);             img.setbackgroundresource(r.drawable.spicejet);              img.setlayoutparams(params);             imageview img1=new imageview(this);             img1.setbackgroundresource(r.drawable.book);             img1.setlayoutparams(params);             imageview img2=new imageview(this);             img2.setbackgroundresource(r.drawable.arrow);             img2.setlayoutparams(params);              textview text = new textview(this);             text.settext("bos");             text.setlayoutparams(params);             textview text1 = new textview(this);             text1.settext("san");             text1.setlayoutparams(params);             textview text2 = new textview(this);             text2.settext("6h15m");             text2.setlayoutparams(params);             textview text3 = new textview(this);             text3.settext("32,163");             text3.setlayoutparams(params);              linearlayout book_div = new linearlayout(this);             book_div.setorientation(linearlayout.vertical);             book_div.setlayoutparams(params);              book_div.addview(text3);             book_div.addview(img1);              hr_populate.addview(img);             hr_populate.addview(text);             hr_populate.addview(text1);             hr_populate.addview(text2);             hr_populate.addview(book_div);             hr_populate.addview(img2);             populate.addview(hr_populate);         }     } 

this xml code

<scrollview          android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:layout_margintop="10dp"         android:layout_below="@+id/sortflightlayouts">          <linearlayout android:layout_width="fill_parent"             android:layout_height="wrap_content"             android:id="@+id/populate"             android:orientation="vertical">         </linearlayout>      </scrollview> 

please suggest me changes have make out issue

try setting imageview's scaletype fitcenter. here example of different scale types: http://etcodehome.blogspot.com/2011/05/android-imageview-scaletype-samples.html


Comments