Android and android Official Website

Source: Internet
Author: User

Android and android Official Website
Dry Goods

DisplayMetrics dm = new DisplayMetrics();  this.getWindowManager().getDefaultDisplay().getMetrics(dm);  screenWidth = dm.widthPixels;  screenHeight = dm.heightPixels;  density = dm.density;  densityDpi = dm.densityDpi;  scaledDensity = dm.scaledDensity;    DisplayMetrics metrics = dm;  Log.i("yydcdut", "metrics::density=" + metrics.density              +", densityDpi="+metrics.densityDpi              +", heightPixels="+metrics.heightPixels              +", widthPixels="+metrics.widthPixels              +", scaledDensity="+metrics.scaledDensity              +", xdpi="+metrics.xdpi              +", ydpi="+metrics.ydpi);

Log output:

metrics::density=1.5, densityDpi=240, heightPixels=854, widthPixels=480, scaledDensity=1.5, xdpi=239.05882, ydpi=243.72585
  • Metrics. widthPixels screen width
  • Metrics. heightPixels screen height
  • Metrics. density screen density

The DisplayMetrics constructor does not need to pass any parameters. After getWindowManager () is called, Handle of the existing Activity is obtained. At this time, the getdefadisplay display () method stores the obtained width and height dimensions in the DisplayMetrics object, the obtained width and height dimensions are measured in pixels. "pixels" refer to "absolute pixels" rather than "relative pixels ".

I am the dividing line of tiantiao

Related Article

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.