android - ImageView image not resizing with ImageView -
i have tablelayout cells of imageview
s. trying create zooming effect incrementing size of imageview
s in tabel. works zooming out( picture resizes imageview
) but, problem zooming in. picture not resize when imageview
made bigger.
here example:
i want image same size imageview(each black square imageview)
here code zooming ( tips on better implementation appreciated, don't want use pinch zoom ).
zoomindex ranges -2, 2. (only allow them zoom twice in each direction) zoominthreshold = 2, zoomoutthreshold = -2. defaultsize = 50, zoomincrement = 15; if(zoomindex < zoominthreshold) defaultsize += zoomincrement; for(int = 0; < table.getchildcount(); ++i) { tablerow row = (tablerow)table.getchildat(i); for(int r = 0; r < row.getchildcount(); ++r) { imageview img = (imageview)row.getchildat(r); if(zoomindex < zoominthreshold) { tablerow.layoutparams imglayoutparams = new tablerow.layoutparams( defaultsize, defaultsize ); img.setlayoutparams(imglayoutparams); if(img.getdrawable() != null) { img.setadjustviewbounds(true); img.setmaxheight(defaultsize); img.setmaxwidth(defaultsize); img.setscaletype(imageview.scaletype.center_inside); } } } } if(zoomindex < zoominthreshold) zoomindex++;
figured out problem, problem happens when load drawings xml files. had add line when loading drawing
img.setadjustviewbounds(true);
this how fits in:
if(drawableid != -1) { bitmap pic = bitmapfactory.decoderesource(getresources(), drawableid); bitmap resizedbitmap = bitmap.createscaledbitmap(pic, 50, 50, true); im.setimagebitmap(resizedbitmap); ic.setimage(im); im.settag(ic); im.setadjustviewbounds(true); //rotate icon im.setscaletype(imageview.scaletype.matrix); matrix matrix = new matrix(); matrix.set(im.getimagematrix()); matrix.postrotate(rotangle, pic.getwidth() / 2, pic.getheight() / 2); im.setimagematrix(matrix); im.setonlongclicklistener(longlisten);//only set listener if there there }
i had img.setadjustviewbounds(true);
in zoom buttons press.
Comments
Post a Comment