android - ImageView size is not displayed correctly -


i'm having problem of displaying imageviews correct size. posts i've read through involves imageviews created in layout file. in case, i'm creating imageviews programmatically.

i'm trying display images particular folder located in storage. bitmaps retrieved placed in imageviews contained within gridview.

here's code:

//pass array containing images paths adapter imagegrid.setadapter(new gridviewadapter(getactivity(), filepathstrings)); 

part of gridvewadapter code:

public view getview(int position, view convertview, viewgroup parent) {             imageview imageview;              if(convertview == null){                 imageview = new imageview(mcontext);                 imageview.setlayoutparams(new gridview.layoutparams(viewgroup.layoutparams.match_parent, viewgroup.layoutparams.match_parent));                 imageview.setscaletype(imageview.scaletype.fit_xy);                 imageview.setpadding(5, 5, 5, 5);                 imageview.setadjustviewbounds(true);              }else{                 imageview = (imageview) convertview;             }              imageview.settag(filepath[position]);             new loadimages(imageview).execute();              return imageview;         } 

asynctask retrieve bitmaps:

private class loadimages extends asynctask<object, void, bitmap> {          private imageview imgview;         private string path;          private loadimages(imageview imgview) {             this.imgview = imgview;             this.path = imgview.gettag().tostring();         }          @override         protected bitmap doinbackground(object... params) {             bitmap bitmap = null;              bitmapfactory.options bmoptions = new bitmapfactory.options();             bmoptions.injustdecodebounds = false;             bmoptions.insamplesize = 6;              bitmap = bitmapfactory.decodefile(path, bmoptions);             try {                  int dimension = getsquarecropdimensionforbitmap(bitmap);                 bitmap = thumbnailutils.extractthumbnail(bitmap, dimension, dimension);              }catch (exception e) {                 e.printstacktrace();             }              return bitmap;         }          @override         protected void onpostexecute(bitmap result) {              if (!imgview.gettag().tostring().equals(path)) {                 return;             }              if(result != null && imgview != null){                 imgview.setvisibility(view.visible);                 imgview.setimagebitmap(result);              }else{                 imgview.setvisibility(view.gone);             }         }     } 

method equal dimensions bitmaps displayed squares:

private int getsquarecropdimensionforbitmap(bitmap bitmap) {             int dimension;             //if bitmap wider height use height square crop dimension              if (bitmap.getwidth() >= bitmap.getheight())    {                 dimension = bitmap.getheight();             }             //if bitmap taller width use width square crop dimension             else    {                 dimension = bitmap.getwidth();             }             return dimension;      } 

gridview in layout file:

    <gridview     android:id="@+id/imagegridview"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:columnwidth="30dp"     android:numcolumns="5"     android:verticalspacing="5dp"     android:horizontalspacing="5dp"     android:stretchmode="columnwidth"     android:gravity="center"     android:layout_margintop="30dp">  </gridview> 

the result i've gotten:

imgview_result

the circled thin "lines" imageviews displayed.

any appreciated. thank in advance!

<gridview android:id="@+id/imagegridview" android:layout_width="match_parent" android:layout_height="fill_parent" android:numcolumns="auto_fit" android:verticalspacing="5dp" android:horizontalspacing="5dp" android:stretchmode="columnwidth" android:gravity="center" android:layout_margintop="30dp"> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -