自定义Dialog位置相对于指定控件

来源:互联网 发布:淘宝店主怎么开通直播 编辑:程序博客网 时间:2024/04/29 11:08
public static Dialog showPrivacyExpandDialog(Activity context, View viewRelative, OnClickListener mLis,int layoutId) {         Dialog mDialog = new Dialog(context, R.style.mydialog);// 创建Dialog并设置样式主题        View view = mDialog.getWindow().getLayoutInflater().inflate(layoutId, null);        mDialog.setContentView(view);         Window win = mDialog.getWindow();        win.setGravity(Gravity.RIGHT | Gravity.TOP);        WindowManager.LayoutParams lp = win.getAttributes();          //set dialog window lp        lp.width=300;//px        lp.height=300;        lp.dimAmount = 0f;/**set windows background 1.0不变暗*/        int screenWidth = context.getWindowManager().getDefaultDisplay().getWidth();               //set 偏移,相对于gravity定义的起始位置        lp.x = screenWidth - viewRelative.getRight();        lp.y = viewRelative.getBottom();        mDialog.setCanceledOnTouchOutside(true);// 设置点击Dialog外部任意区域关闭Dialog        mDialog.show();        return mDialog;    }


0 0
原创粉丝点击