/**
* 弹出框PopupWindow,点击图片查看大图
*/
private PopupWindow popWindow;
private int width_pop, height;//屏幕高度、宽度
private LinearLayout linear;
private void initPopupWindow(View view3, String path) {
ProgressDialogUtils.showProgressDialog("加载中", context, false);
LayoutInflater inflater = LayoutInflater.from(context);
// 引入窗口配置文件
View view1 = inflater.inflate(R.layout.image_pop1, null);
DisplayMetrics metric = new DisplayMetrics();
((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(metric);
width_pop = metric.widthPixels;
height = metric.heightPixels;
ImageView image = (ImageView) view1.findViewById(R.id.image);
linear = (LinearLayout) view1.findViewById(R.id.linear);
linear.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popWindow.dismiss();
}
});
popWindow = new PopupWindow(view1, ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT, false);
backgroundAlpha(0.5f);
popWindow.setBackgroundDrawable(new BitmapDrawable());
popWindow.setOutsideTouchable(true);
popWindow.setFocusable(true);
popWindow.setTouchable(true);
popWindow.update();
popWindow.setTouchInterceptor(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
popWindow.dismiss();
return true;
}
return false;
}
});
popWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
backgroundAlpha(1.0f);
}
});
new NormalLoadPictrue().getPicture(path, image);
popWindow.showAtLocation(view3, Gravity.CENTER, 0, 0);
}
//背景Alpha
public void backgroundAlpha(float bgAlpha) {
WindowManager.LayoutParams lp = ((Activity) context).getWindow().getAttributes();
lp.alpha = bgAlpha; //0.0-1.0
((Activity) context).getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
((Activity) context).getWindow().setAttributes(lp);
}
弹出框PopupWindow,点击图片查看大图
最新推荐文章于 2023-03-17 14:37:18 发布