Public classDimenutil {/**sp converted to PX*/ Public Static intSP2PX (floatspvalue) { floatFontscale =Myapplication.getcontext (). Getresources (). Getdisplaymetrics (). scaleddensity; return(int) (Spvalue * Fontscale + 0.5f); } /**px conversion to SP*/ Public Static intPX2SP (floatpxvalue) { floatFontscale =Myapplication.getcontext (). Getresources (). Getdisplaymetrics (). density; return(int) (Pxvalue/fontscale + 0.5f); } /**dip conversion into PX*/ Public Static intDIP2PX (floatdipvalue) { floatScale =Myapplication.getcontext (). Getresources (). Getdisplaymetrics (). scaleddensity; return(int) (Dipvalue * scale + 0.5f); } /**px converted into dip*/ Public Static intPx2dip (floatpxvalue) { floatScale =Myapplication.getcontext (). Getresources (). Getdisplaymetrics (). scaleddensity; return(int) (Pxvalue/scale + 0.5f); }}
Dimenutil of the common Android tool class