AlertDialog, одно и то же изображение отображается с разным размером - PullRequest
0 голосов
/ 05 мая 2019

Мне было интересно, может ли кто-нибудь мне помочь. Я пытаюсь создать AlertDialog, где я показываю изображение, используя PhotoView для увеличения.

Для этого в классе Fragment я использую этот код

            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" />

Когда я использую изображение, находящееся в папке drawable, AlertDialog изображение отображается с нужным размером.

mPhotoView.setImageResource(R.drawable.scenery);

рисует

Однако, я не могу показать желаемый размер, когда изображение в external memory.

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

внешняя память

Может ли кто-нибудь помочь мне с этим?

1 Ответ

0 голосов
/ 05 мая 2019

Я уже исправил это.

<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>
...