1.获取控件在屏幕中位置
int[] location = new int[2];
View.geiewtLocationOnScreen(location);
int heihtView=moreOrderTabWX.getMeasuredHeight();
int widthView=moreOrderTabWX.getMeasuredWidth();
2.设置Dialog显示到指定位置
Window window = dialog.getWindow();
WindowManager.LayoutParams params = window.getAttributes();
params.x =5;
params.y =100;
window.setAttributes(params);
window.setGravity(Gravity.TOP|Gravity.LEFT);
dialog.show();
3.自定义Dialog(仅作记录,读者勿作参考)
public class ErweiMaDialog extends Dialog {
public ErweiMaDialog(Context context) {
this(context,R.style.dialog_0);
}
public ErweiMaDialog(Context context, int theme) {
super(context, theme);
}
public static class Builder {
private Context context;
public Builder(Context context) {
this.context = context;
}
public ErweiMaDialog create(Bitmap bitmap) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ErweiMaDialog dialog = new ErweiMaDialog(context);
View layout = inflater.inflate(R.layout.wechat_erweima, null);
dialog.addContentView(layout, new ViewGroup.LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT
, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
dialog.setContentView(layout);
return dialog;
}
}
}