Android accurately obtains the screen size (e.g. 3.5, 4.0, 5.0 inch screen)
•
Java
Here is the programming house jb51 CC collects and arranges code fragments through the network.
Programming house Xiaobian now shares it with you and gives you a reference.
public static double getScreenPhysicalSize(Activity ctx) { DisplayMetrics dm = new DisplayMetrics(); ctx.getWindowManager().getDefaultDisplay().getMetrics(dm); double diagonalPixels = Math.sqrt(Math.pow(dm.widthPixels,2) + Math.pow(dm.heightPixels,2)); return diagonalPixels / (160 * dm.density); }
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码