中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Android開發(fā)中常用屏幕單位轉(zhuǎn)換

2018-07-20    來源:open-open

容器云強(qiáng)勢上線!快速搭建集群,上萬Linux鏡像隨意使用
public class DisplayTool {
   //要根據(jù)實際情況獲取到上下文Context,也可以在方法中加入context作為參數(shù)
    private static final float density = context.getResources().getDisplayMetrics().density;
    private static final float scaledDensity =context.getResources().getDisplayMetrics().scaledDensity;

    /**
     * 將px值轉(zhuǎn)換為dip或dp值,保證尺寸大小不變
     */
    public static int px2dip(float pxValue) {
        return (int) (pxValue / density + 0.5f);
    }

    /**
     * 將dip或dp值轉(zhuǎn)換為px值,保證尺寸大小不變
     */
    public static int dip2px(float dipValue) {
        return (int) (dipValue * density + 0.5f);
    }

    /**
     * 將px值轉(zhuǎn)換為sp值,保證文字大小不變
     */
    public static int px2sp(float pxValue) {
        return (int) (pxValue / scaledDensity + 0.5f);
    }

    /**
     * 將sp值轉(zhuǎn)換為px值,保證文字大小不變
     */
    public static int sp2px(float spValue) {
        return (int) (spValue * scaledDensity + 0.5f);
    }

}

標(biāo)簽: isp

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:Android用SurfaceView播放本地視屏(音頻)文件

下一篇:Android利用Volley框架加載網(wǎng)絡(luò)圖片