private void iniPopupWindow() {html
LayoutInflater inflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.task_detail_popupwindow, null);
pwMyPopWindow = new PopupWindow(layout);
pwMyPopWindow.setFocusable(true);// 加上这个popupwindow中的ListView才能够接收点击事件ide
lvPopupList.setAdapter();布局
// 控制popupwindow点击屏幕其余地方消失
pwMyPopWindow.setBackgroundDrawable(this.getResources().getDrawable(
R.drawable.bg_popupwindow));// 设置背景图片,不能在布局中设置,要经过代码来设置
pwMyPopWindow.setOutsideTouchable(true);// 触摸popupwindow外部,popupwindow消失。这个要求你的popupwindow要有背景图片才能够成功,如上ui
// 更多操做按钮
ibOperationMore = (ImageButton) findViewById(R.id.ib_operate_more);
ibOperationMore.setOnClickListener(new OnClickListener() {this
@Override
public void onClick(View v) {spa
if (pwMyPopWindow.isShowing()) {.net
pwMyPopWindow.dismiss();// 关闭
} else {code
pwMyPopWindow.showAsDropDown(ibOperationMore);// 显示
}htm
}
});对象
在Android中咱们常常会用AlertDialog来显示对话框。经过这个对话框是显示在屏幕中心的。但在某些程序中,要求对话框能够显示在不一样的位置。例如,屏幕的上方或下方。要实现这种效果。就须要得到对话框的Window对象,得到这个Window对象有多种方法。最容易的就是直接经过AlertDialog类的getWindow方法来得到Window对象。
AlertDialog dialog = new AlertDialog.Builder(this).setTitle("title")
.setMessage("message").create();
Window window = alertDialog.getWindow();
window.setGravity(Gravity.TOP); //window.setGravity(Gravity.BOTTOM);
alertDialog.show();
透明的对话框
默认显示的对话框是不透明的,但咱们能够经过设置对话框的alpha值将其变成透明或半透明效果。咱们都知道。颜色由R(红)、G(绿)、B(蓝)组成。除此以外,还会有一个A(透明度,Alpha)来描述颜色。在颜色的描述中,若是该值为0表示彻底透明,若是该值为255,表示不透明。
经过设置Windows的alpha属性也能够设置对话框的透明度。但alpha的取值范围是从0到1.0。若是该属性值为0,表示彻底透明,若是该值为1.0,表示不透明(也就是正常显示的对话框)。
透明的对话框。在本例中加了一个背景图像,将同时显示了两个对话框(一个是半透明的,另外一是不透明的)。
//显示透明的对话框
AlertDialog alertDialog = new AlertDialog.Builder(this).setMessage(
"透明对话框").setPositiveButton("肯定", null).create();
Window window = alertDialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
// 设置透明度为0.3
lp.alpha = 0.6f;
window.setAttributes(lp);
alertDialog.show();
咱们在使用某些应用时会发现当弹出对话框或某些模式窗口时,后面的内容会变得模糊或不清楚。实际上,这些效果也很容易在OPhone中实现。为了实现这个功能,咱们只须要设置Wndow对象的两个标志便可,代码以下:
window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
popupWindow 在控件的各个方向上的显示(上、下、左、右)
http://blog.csdn.net/dxj007/article/details/8026691
// 相对某个控件的位置(正左下方),无偏移pop.showAsDropDown(View anchor) // 相对某个控件的位置,有偏移,xoff 为 X 轴的偏移量,yoff 为 Y 轴的偏移量 pop.showAsDropDown(View anchor, int xoff, int yoff)// 在父容器的什么位置,gravity 为相对位置,如:正中央 Gravity.CENTER、下方 Gravity.BOTTOM、Gravity.RIGHT|Gravity.BOTTOM 右下方等,后面两个参数为 x/y 轴的偏移量。pop.showAtLocation(View parent, int gravity, int x, int y)
dialog对话框:
http://www.cnblogs.com/angeldevil/archive/2012/03/31/2426242.html
dialogLayoutParams.width = LocalUtils.getScreen(context)[0]/2+70;
dialogLayoutParams.height = LocalUtils.getScreen(context)[1]/3+50;
dialogLayoutParams.y=50;
window.setAttributes(dialogLayoutParams);
window.setGravity(Gravity.BOTTOM);
这样设置会使对话框距离底部50