Android Image Dialog/Popup same size as image and no border -


at moment working on file browser. works fine 1 exception: if user clicks on image (jpg, png, bmp, ..), want image displayed in dialog or in popup has same size image - there no borders @ all. image files located on sdcard.

here have far:

bitmapdrawable bitmap = new bitmapdrawable(context.getresources(), target_path);  alertdialog.builder imagedialog = new alertdialog.builder(context); layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_service);  view layout = inflater.inflate(r.layout.thumbnail, null); imageview image = (imageview) layout.findviewbyid(r.id.thumbnail_imageview); image.setimagedrawable(bitmap); imagedialog.setview(layout); imagedialog.create(); imagedialog.show(); 

the xml file:

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent" >      <imageview         android:id="@+id/thumbnail_imageview"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:contentdescription="@string/icon_description" />  </relativelayout> 

here output:

fail output

there ugly borders @ edges of images - don't want them shown. tried lots of stuff , examples listed in google, etc.. - nothing worked yet.

the best option make dialog/the view behind image, same size image. way set background behind image transparent.

how achieve solution? i'd love make background same size image is, there no "invisible" stuff left, okay transparent option.


solution:

// screen size display display = context.getwindowmanager().getdefaultdisplay(); point size = new point(); display.getsize(size); int screenwidth = size.x; int screenheight = size.y;  // target image size bitmap bitmap = bitmapfactory.decodefile(target); int bitmapheight = bitmap.getheight(); int bitmapwidth = bitmap.getwidth();  // scale image down fit screen // value (250 in case) must adjusted phone/tables displays while(bitmapheight > (screenheight - 250) || bitmapwidth > (screenwidth - 250)) {     bitmapheight = bitmapheight / 2;     bitmapwidth = bitmapwidth / 2; }  // create resized bitmap image bitmapdrawable resizedbitmap = new bitmapdrawable(context.getresources(), bitmap.createscaledbitmap(bitmap, bitmapwidth, bitmapheight, false));  // create dialog dialog dialog = new dialog(context); dialog.requestwindowfeature(window.feature_no_title); dialog.setcontentview(r.layout.thumbnail);  imageview image = (imageview) dialog.findviewbyid(r.id.imageview);  // !!! here setbackground() instead of setimagedrawable() !!! // image.setbackground(resizedbitmap);  // without line there small border around image (1px) // in opinion looks better without it, choice you. dialog.getwindow().setbackgrounddrawable(null);  // show dialog dialog.show(); 

xml file:

<?xml version="1.0" encoding="utf-8"?> <imageview xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/imageview"     android:layout_width="match_parent"     android:layout_height="match_parent" >  </imageview> 

final output:

output

you can make custom dialog showing images , make layout inflating in dialog's setcontentview , take 1 linear layout width , height wrap content , imageview in scale property fitxy .


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -