dp 与px互相转换
生活随笔
收集整理的這篇文章主要介紹了
dp 与px互相转换
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/** * 根據手機的分辨率從 dp 的單位 轉成為 px(像素) */ public static int dip2px(Context context, float dpValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (dpValue * scale + 0.5f); } /** * 根據手機的分辨率從 px(像素) 的單位 轉成為 dp */ public static int px2dip(Context context, float pxValue) { final float scale = context.getResources().getDisplayMetrics().density; return (int) (pxValue / scale + 0.5f); }
總結
以上是生活随笔為你收集整理的dp 与px互相转换的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 倒计时的CountDownTimer
- 下一篇: android:descendantFo