Dialog setting view cannot be centered. dialog setting view Center
Today, when I typed the code, I found that when I set my own view for dialog, I couldn't center the display. It was always printed above the dialog. The Code is as follows:
AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(R.layout.quick_login_dialog); builder.setCancelable(false); AlertDialog alertDialog = builder.create(); alertDialog.show(); int width = DImenUtil.dip2px(this, 150); int height = DImenUtil.dip2px(this, 130); alertDialog.getWindow().setLayout(width,height); alertDialog.getWindow().setBackgroundDrawableResource(R.drawable.quick_login_background);
The xml Code is as follows:
When dialog parses xml, it only recognizes the second-level layout. The second-level layout height changes, and the overall layout height changes, that is, we should regard the Layer 2 Layout as the root layout. The modified xml is as follows:
That is to say, we need to nest another layer and use the nested sub-layout as the root layout. The first layer does not matter because it is useless.