In android, based on the conversion of dp and px at different resolutions, the android resolution dppx
Public class PxAndDp {/*** convert the unit from dp to px (pixel) */public static int dip2px (Context context, float dpValue) based on the resolution of the mobile phone) {final float scale = context. getResources (). getDisplayMetrics (). density; return (int) (dpValue * scale + 0.5f);}/*** based on the resolution of the phone) to dp */public static int px2dip (Context context, float pxValue) {final float scale = context. getResources (). getDisplayMetrics (). density; return (int) (pxValue/scale + 0.5f );}}
In Android, how does one convert between dp and px?
How is the conversion between the height of the android control and the unit of broadband sp px dp?
Android performs unit Conversion Based on resolution-(dp, sp to pixel px). For more information about this article, see the original post>