实现点击图片看大图以及dialog背景设置透明

 LayoutInflater inflater = LayoutInflater.from(context);
 View imgEntryView = inflater.inflate(R.layout.dialog_photo_entry, null); // 加载自定义的布局文件
 final AlertDialog dialog = new AlertDialog.Builder(context).create();
 ImageView img = (ImageView)imgEntryView.findViewById(R.id.large_image);

// imageDownloader.download("图片地址",img); // 这个是加载网络图片的,可以是自己的图片设置方法
 Glide
         .with(context)
         .load(list.get(index))
         .into(img);
 dialog.setView(imgEntryView); // 自定义dialog
 Window win = dialog.getWindow();
 // 一定要设置Background,如果不设置,window属性设置无效
 win.setBackgroundDrawable( new ColorDrawable(Color.TRANSPARENT));
 dialog.show();
     //大图的点击事件(点击让他消失)
 imgEntryView.setOnClickListener(new View.OnClickListener() {
     public void onClick(View paramView) {
         dialog.cancel();
     }
 });
 
 



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <ImageView android:layout_height="wrap_content"
        android:id="@+id/large_image"
        android:layout_width="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true">
    </ImageView>
</RelativeLayout>

猜你喜欢

转载自blog.csdn.net/qq_35661481/article/details/79971297
今日推荐