安卓中像素px和dp的转换: public int Dp2Px(Context context, float dp) { final float scale = context.getResources().getDisplayMetrics().density; //当前屏幕密度因子 return (int) (dp * scale + 0.5f); } public int Px2Dp(Context context, float px) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (px / scale + 0.5f); }