我想知道是否有人可以帮助我。我正在尝试创建一个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);
有人可以帮我吗?
答案 0 :(得分:0)
我已经修复了它。
<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>