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