I was wondering if someone could help me. I'm trying to create an AlertDialog where I show an image using PhotoView to zoom in.

To do this in a Fragment class I am using this code

            AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); 
            View mView = getLayoutInflater().inflate(R.layout.esta_cre, null);
            PhotoView mPhotoView = mView.findViewById(R.id.image_esq);
            File imageFile = new File(Environment.getExternalStorageDirectory() + "/Pictures/scenery.jpg");
            Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
            mPhotoView.setImageBitmap(bitmap);

            // mPhotoView.setImageResource(R.drawable.scenery);   

            mPhotoView.setScaleType(ImageView.ScaleType.CENTER_CROP);  

            alert.setView(mView)
                    .setPositiveButton("Cerrar", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.cancel();
                        }
                    });

            AlertDialog mDialog = alert.create();
            mDialog.show();

XML

  <com.github.chrisbanes.photoview.PhotoView
      android:id="@+id/image_esq"
      android:layout_width="match_parent"
      android:layout_height="match_parent" />

When I use the image that is in the drawable folder, AlertDialog the image is displayed with the desired size.

mPhotoView.setImageResource(R.drawable.scenery);

drawable

However, I can't seem to show the desired size when the image is in the external memory.

File imageFile = new File(Environment.getExternalStorageDirectory() + "/Pictures/scenery.jpg"); Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath()); mPhotoView.setImageBitmap(bitmap);

external memory

Can someone help me with this?

1 Answers

0
SoCu On

I've already fixed it.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/frameLayout"
    android:background="#b2ff7c">

    <com.github.chrisbanes.photoview.PhotoView
    android:id="@+id/image_esque_crevi"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:scaleType="center" />

</FrameLayout>

</RelativeLayout>