Wednesday, 7 August 2013

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

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

At the moment I am working on a file browser. Everything works fine with
one exception: If the user clicks on an image (jpg, png, bmp, ..), I want
the image to be displayed in a dialog or in a popup which has the same
size as the image - so that there are no borders at all. The image files
are located on the sdcard.
Here is what I have so 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 is the output:

..and here another one:

There are ugly borders on the sides of the images - I don't want them to
be shown. I tried plenty of examples listed in google, etc.. but nothing
worked.
The best option will be to make the dialog/the view behind the image, the
same size as the image. Another way could be to set the background behind
the image transparent.
How do I achieve any solution? I'd love to make the background the same
size as the image is, so there is no "invisible" stuff left, but I will
also be okay with the transparent option.

No comments:

Post a Comment