Java code
Display display = getWindowManager (). getDefaultDisplay ();
Display. getWidth (); // returns the px value.
Display. getHeight (); // returns the px value.
Display. getRotation (); 0 or 1 is returned, indicating a portrait screen, and 1 is a landscape screen.
DisplayMetrics dm = new DisplayMetrics ();
GetWindowManager (). getDefaultDisplay (). getMetrics (dm );
Dm. density;
Dm. heightPixels;
Dm. widthPixels;
Let's look at the relationship between the two.
Sdk code snippets
Public void getMetrics (DisplayMetrics outMetrics ){
OutMetrics. widthPixels = getWidth ();
OutMetrics. heightPixels = getHeight ();
OutMetrics. density = mDensity;
OutMetrics. densityDpi = (int) (mDensity * DisplayMetrics. DENSITY_DEFAULT) +. 5f );
OutMetrics. scaledDensity = outMetrics. density;
OutMetrics. xdpi = mDpiX;
OutMetrics. ydpi = mDpiY;
}
// Only assign the internal value of Display to the attribute value of DisplayMetrics
Author "program life"