<dimen name="margin_dp">3dp</dimen>
<dimen name="margin_px">3px</dimen>
<dimen name="margin_sp">3sp</dimen>
DisplayMetrics dd = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dd);
Log.i(TAG,"Phone size:"+dd.widthPixels+"X"+dd.heightPixels);
DisplayMetrics metric = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metric);
int width = metric.widthPixels; // 屏幕宽度(像素)
int height = metric.heightPixels; // 屏幕高度(像素)
float density = metric.density; // 屏幕密度(0.75 / 1.0 / 1.5)
int densityDpi = metric.densityDpi; // 屏幕密度DPI(120 / 160 / 240)
Log.i(TAG,"Phone size:"+dd.widthPixels+"X"+dd.heightPixels+",密度比:"+metric.density+",密度值dpi:"+metric.densityDpi);
float a1=getResources().getDimension(R.dimen.margin_dp);
int a2=getResources().getDimensionPixelOffset(R.dimen.margin_dp);
int a3=getResources().getDimensionPixelSize(R.dimen.margin_dp);
Log.i(TAG, "dp_value_read= "+"a:"+"getDimension"+a1+", getDimensionPixelOffset="+a2+",getDimensionPixelSize="+a3);
float b1=getResources().getDimension(R.dimen.margin_px);
int b2=getResources().getDimensionPixelOffset(R.dimen.margin_px);
int b3=getResources().getDimensionPixelSize(R.dimen.margin_px);
Log.i(TAG, "px_value_read= "+"a:"+"getDimension"+b1+", getDimensionPixelOffset="+b2+",getDimensionPixelSize="+b3);
float c1=getResources().getDimension(R.dimen.margin_sp);
int c2=getResources().getDimensionPixelOffset(R.dimen.margin_sp);
int c3=getResources().getDimensionPixelSize(R.dimen.margin_sp);
Log.i(TAG, "sp_value_read= "+"a:"+"getDimension"+c1+", getDimensionPixelOffset="+c2+",getDimensionPixelSize="+c1);
/*
小米4c xxhdpi適配 1920X1080实际打印值
space.qssq.testkey I/MainActivity: Phone size:1920X1080,密度比:3.0,密度值dpi:480\dp_value_read= a:getDimension9.0, getDimensionPixelOffset=9,getDimensionPixelSize=9
\MainActivity: px_value_read= a:getDimension3.0, getDimensionPixelOffset=3,getDimensionPixelSize=3
\ainActivity: sp_value_read= a:getDimension9.0, getDimensionPixelOffset=9,getDimensionPixelSize=9.0
*/标签:dimen,Log,int,margin,getDimensionPixelSize,getDimension,getDimensionPixelOffset, From: https://blog.51cto.com/u_15458814/5882968
}