First, to introduce the following about PX, PT, PPI, DPI, DP knowledge
Terms |
Description |
Px |
(pixel), pixel, the most basic point on the screen to display data |
Pt |
(point), Dot 1pt=1/72 inch |
Ppi |
(pixel per inch), number of pixels in each inch |
Dpi |
(dot/inch), dots per inch |
Dp |
i.e. dip (density-independent pixel), device independent pixel 1dp=160dpi 1px length |
where PX, PT, DP for length units, PPI and dpi for density units
Density |
ldpi |
mdpi |
hdpi |
xhdpi |
xxhdpi |
Density value |
120 |
160 |
240 |
320 |
480 |
Resolution |
240*320 |
320*480 |
480*800 |
720*1280 |
1080*1920 |
Icon size |
36*36 |
48*48 |
72*72 |
96*96 |
144*144 |
Two, the following provide several commonly used methods
1. Get screen height
public int getrealheight (activity activity) {
int heightpixels = 0;
Display display = Activity.getwindowmanager (). Getdefaultdisplay ();
Final int VERSION = Build.VERSION.SDK_INT;
if (VERSION <) {
display.getheight ();
} else if (VERSION = =
try {
heightpixels = (Integer) Display.class.getMethod ("Getrawheight"). Invoke (Display );
} catch (Exception e) {
}
} else {point
realsize = new Point ();
try {
Display.class.getMethod ("Getrealsize", Point.class). Invoke (Display, realsize);
Heightpixels = realsize.y;
} catch (Exception e) {
}
} return
heightpixels
}
2. Get screen density
/**
* Get screen density
* @return
/public static float getscreendensity (activity activity) {
Displaymetrics displaymetrics = new Displaymetrics ();
Activity.getwindowmanager (). Getdefaultdisplay (). Getmetrics (displaymetrics);
return displaymetrics.density;
}
3, get the screen can operate area width DP number
/**
* Get screen operable area width DP number
*
* @param activity * @return/public
Static float GETSCREENWIDTHDP (activity activity) {return
getscreenwidth (activity)/getscreendensity (activity);
}
4, obtain the screen height can operate the area DP number
/**
* Get screen height operable area DP Number
*
* @param activity * @return/public
Static float GETSCREENHEIGHTDP (activity activity) {return
getscreenheight (activity)/getscreendensity (activity);
}
5, get the screen true width DP number
/**
* Get screen True width DP number
*
* @param activity
* @return
/public static float GETREALWIDTHDP ( Activity activity) {return
getrealwidth (activity)/getscreendensity (activity);
}
6, get the screen true height DP number
/**
* Get screen True height DP number
*
* @param activity
* @return/public
static float GETREALHEIGHTDP (Activity activity) {return
getrealheight [activity]/getscreendensity (activity);
}
7, to determine whether the plate
public static Boolean Istablet [activity activity] {return
ismorethan6inch (activity) && Isscreensizelarge (activity);
}
/**
* Determine if greater than 6 inches
* @param activity
* @return
/Public
static Boolean ismorethan6inch ( Activity activity) {return
getscreeninch (activity) >= 6.0
}
/**
* Determine if the device is a large size screen
*
* @param context
* @return
/Public
static Boolean Isscreensizelarge ( Context context) {return
(Context.getresources (). GetConfiguration (). Screenlayout & Configuration.screenlayout_size_mask) >= configuration.screenlayout_size_large;
}
Summarize
This is all about the Android screen knowledge Point, I hope the content of this article for your Android developers can help, if you have questions you can message exchange.