Android PopulWindow创建与定位

创建一个PopulWindow

if (popupWindow != null && popupWindow.isShowing()) {  
    popupWindow.dismiss();  
    return;  
}  
int popWidth = Common.dip2px(this, 120);  
View contentView = getLayoutInflater().inflate(R.layout.pop, null);  
WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);  
popupWindow = new PopupWindow(contentView, popWidth,  
        LayoutParams.WRAP_CONTENT, true);  
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));  
int xOff = windowManager.getDefaultDisplay().getWidth() / 2  
        - popupWindow.getWidth() / 2;  
popupWindow.showAsDropDown(view, xOff, 0);  
popupWindow.update();  


 

 

定位:

populWindow.showAsDropDown(view)——>   以view的左下角作为参照,位于view的下方

populWindow.showAsDropDown(view,xoff,yoff)——> 以view 的左下角作为参照,同时可以设置偏移

mPop.showAtLocation(parent, Gravity.CENTER, 0, 0);  以parent为参照物。


原文地址:http://blog.csdn.net/liangguo03/article/details/7335538

你可能感兴趣的:(Android PopulWindow创建与定位)