Dialog setting view cannot be centered. dialog setting view Center

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.