0

I'm trying to make a custom alertdialog with an ImageView inside:

public static void showFullSizePhoto(ImageView imageView, Context context) {

    ImageView tempImageView = imageView;

    AlertDialog.Builder imageDialog = new AlertDialog.Builder(context);
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(LAYOUT_INFLATER_SERVICE);

    View layout = inflater.inflate(R.layout.image_dialog,
            (ViewGroup) ((Activity) context).findViewById(R.id.layout_root));

    ImageView image = (ImageView) layout.findViewById(R.id.user_fullimage);
    image.setImageDrawable(tempImageView.getDrawable());        
    imageDialog.setView(layout);         
    AlertDialog dialog = imageDialog.create();  
    dialog.show();          
}   

image_dialog.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root" 
    android:orientation="horizontal"
    android:layout_width="wrap_content" 
    android:layout_height="match_parent">
        <ImageView 
            android:id="@+id/user_fullimage" 
            android:layout_width="wrap_content"
            android:layout_height="match_parent">
        </ImageView>    
</LinearLayout>

However it's not displaying my image correctly(see attached picture). How do I get rid of this white stripe, so the dialog window wraps the image?

image

Valera
  • 423
  • 1
  • 6
  • 16

4 Answers4

0

change your layout as

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
    android:id="@+id/user_fullimage"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scaleType="fitXY">
</ImageView>
</LinearLayout>
Libin
  • 16,967
  • 7
  • 61
  • 83
  • It stretches the image, leaving the size of the dialog window the same. I want to change the size of the window according to the size of the image. Any ideas how to do that? – Valera Mar 29 '14 at 01:26
  • try android:scaleType="centerCrop". – Libin Mar 29 '14 at 03:07
0

Apparently, you can't change the size of AlertDialog, however you can try using Dialog instead. Here is the solution :

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

Community
  • 1
  • 1
Valera
  • 423
  • 1
  • 6
  • 16
0

Change your lay out to this:

  <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root" 
    android:orientation="horizontal"
    android:layout_width="match_parent" 
    android:layout_height="match_parent">
        <ImageView 
            android:id="@+id/user_fullimage" 
            android:layout_width="wrap_content"
             android:scaleType="fitXY"
            android:layout_height="match_parent">
        </ImageView>    
   </LinearLayout>
Kishan Dhamat
  • 3,746
  • 2
  • 26
  • 36
0

set

 android:scaleType="fitXY"

for your ImageView.