75_popupwindow的使用

来源:互联网 发布:mount默认端口 编辑:程序博客网 时间:2024/05/19 02:18

一、Activity中

PopupWindow  popwindow = new PopupWindow(contentView, -2, -2);   // -2表示wrap_content, -1表示match_parent,正数表示弹出框大小的像素值
// PopupWindow popwindow = new PopupWindow(tv,
// LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
// true);
popwindow.setBackgroundDrawable(new ColorDrawable(
Color.TRANSPARENT));
int[] location = new int[2];
view.getLocationInWindow(location);    //返回view对象的,相对于屏幕的位置,存放到location中(view.getLeft(),是相对于父窗体的位置)
popwindow.showAtLocation(parent,
Gravity.LEFT | Gravity.TOP, DensityUtil.dip2px(getApplicationContext(), location[0] + 70),
location[1]);



private void dismissPopupWindow() {
if (popwindow != null && popwindow.isShowing()) {
popwindow.dismiss();
popwindow = null;


}
}

0 0
原创粉丝点击