[英]Android dialog show top & left
I want to dialog appears in center I use this code . 我想对话框出现在我使用此代码的中心。
public void dialog(View v){
Dialog d=new Dialog(this);
d.setContentView(R.layout.dl_search);
d.setCancelable(true);
d.show();
}
Appear the dialog in center . 将对话框显示在中间。 ![1][1] But when I add this code . ![1] [1] 但是,当我添加此代码时。
d.getWindow().setBackgroundDrawable(new BitmapDrawable(getResources(),blurbitmap));
The dialog appear in top & left . 对话框出现在顶部和左侧。 ![2][2] .... ![2] [2] ....
I want to be dialog in center ** **Thanks for help 我想在中心对话** **谢谢您的帮助
[1]: http:// i.stack.imgur.com/UPT3S.jpg [1]:http:// i.stack.imgur.com/UPT3S.jpg
[2]: http:// i.stack.imgur.com/K0G1w.jpg [2]:http:// i.stack.imgur.com/K0G1w.jpg
Use this: 用这个:
Window window = customdialog.getWindow();
window.setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.CENTER);
or Try: 或尝试:
android:gravity="center_vertical|center_horizontal"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.