您的位置:首页 > 运维架构

弹出框PopupWindow,点击图片查看大图

2016-12-07 11:17 501 查看
/**
* 弹出框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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: