步驟1:一類FullImageDialog
有這個方法:
public static void showImage(Context context, String strImagePath) {
AlertDialog.Builder imageDialog = new AlertDialog.Builder(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_fullimage_dialog, null);
ImageView image = (ImageView) layout.findViewById(R.id.fullImage);
Glide.with(context)
.load(strImagePath)
.placeholder(R.drawable.default_user_image)
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(image);
//image.setImageDrawable(tempImageView.getDrawable());
imageDialog.setView(layout);
final AlertDialog alert= imageDialog.create();
alert.getWindow().getAttributes().windowAnimations=R.style.FadeInTheme;
alert.show();
}
第2步:創建的XML full_image_dialog爲:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout_root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="@+id/fullImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:background="@drawable/default_user_image"
android:scaleType="fitXY" />
</LinearLayout>
第3步:在您需要打開此對話框調用方法:
final ImageView imageView1 = (ImageView) findViewById(R.id.imageView8);
imageView1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//call FullImageDialog class by giving parameter of imageUrl
FullImageDialog.showImage(imageUrl);
}
你需要問一個實際的問題。 – Difster