Image Array for loop Bitmap Android -


how pass imageview array following code. code takes image array resize , put in linearlayout. currenly code take 1 image @ time.

imageview array:

    private integer[] imgid = {                 r.drawable.pic1,                 r.drawable.pic2,                 r.drawable.pic3,          };       bitmap bitmaporg = bitmapfactory.decoderesource(getresources(),                 imgid[5]); // taking 1 image           int width = bitmaporg.getwidth();         int height = bitmaporg.getheight();         int newwidth = 200;         int newheight = 200;          // calculate scale - in case = 0.4f         float scalewidth = ((float) newwidth) / width;         float scaleheight = ((float) newheight) / height;          // createa matrix manipulation         matrix matrix = new matrix();         // resize bit map         matrix.postscale(scalewidth, scaleheight);         // rotate bitmap         matrix.postrotate(0);          // recreate new bitmap         bitmap resizedbitmap = bitmap.createbitmap(bitmaporg, 0, 0,                           width, height, matrix, true);          // make drawable bitmap allow set bitmap         // imageview, imagebutton or ever         bitmapdrawable bmd = new bitmapdrawable(getresources(),resizedbitmap);            linearlayout linearlayout1 = (linearlayout) findviewbyid(r.id.linear);         for(int x=0;x<25;x++) {             imageview imageview = new imageview(this);             imageview.setpadding(2, 0, 9, 5);             imageview.setimagedrawable(bmd);               linearlayout1.addview(imageview);     } 

i rearranged code, works fine. have 25 r.drawable.pic, right? wrong new linearlayout every time add imageview.

private integer[] imgid = {     r.drawable.pic1,     r.drawable.pic2,     r.drawable.pic3, };  linearlayout linearlayout1 = (linearlayout) findviewbyid(r.id.linear); for(int x=0;x<25;x++) {     bitmap bitmaporg = bitmapfactory.decoderesource(getresources(),imgid[x]);       int width = bitmaporg.getwidth();     int height = bitmaporg.getheight();     int newwidth = 200;     int newheight = 200;      // calculate scale - in case = 0.4f     float scalewidth = ((float) newwidth) / width;     float scaleheight = ((float) newheight) / height;      // createa matrix manipulation     matrix matrix = new matrix();     // resize bit map     matrix.postscale(scalewidth, scaleheight);     // rotate bitmap     matrix.postrotate(0);      // recreate new bitmap     bitmap resizedbitmap = bitmap.createbitmap(bitmaporg, 0, 0,                       width, height, matrix, true);      // make drawable bitmap allow set bitmap     // imageview, imagebutton or ever     bitmapdrawable bmd = new bitmapdrawable(getresources(),resizedbitmap);      imageview imageview = new imageview(this);     imageview.setpadding(2, 0, 9, 5);     imageview.setimagedrawable(bmd);                  linearlayout1.addview(imageview); } 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -