Android Gets the width and height of the screen

Source: Internet
Author: User

获取屏幕的宽度与高度有以下几种方法:

1、WindowManager wm = (WindowManager) getContext()

                    .getSystemService(Context.WINDOW_SERVICE);

 

     intwidth = wm.getDefaultDisplay().getWidth();

     intheight = wm.getDefaultDisplay().getHeight();

 

2、WindowManager wm =this.getWindowManager();

 

     intwidth = wm.getDefaultDisplay().getWidth();

     intheight = wm.getDefaultDisplay().getHeight();

3、 DisplayMetrics metric = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metric);
        int width = metric.widthPixels;     // 屏幕宽度(像素)
        int height = metric.heightPixels;   // 屏幕高度(像素)
        float density = metric.density;      // 屏幕密度(0.75 / 1.0 / 1.5)
        int densityDpi = metric.densityDpi;  // 屏幕密度DPI(120 / 160 / 240)

Android Gets the width and height of the screen

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.