android手機尺寸相關p107-p110

來源:互聯網
上載者:User

標籤:

1.ldpi-----240x320-----密度120

 mdpi-----320x480-----密度160

 hdpi-----480x800-----密度240 

 xhdpi-----720x1280-----密度320

 xxhdpi-----1080x1920-----密度480

 

2.mdpi-----1dp=1px

 hdpi-----1dp=1.5px

 xhdpi-----1dp=2px

 xxhdpi-----1dp=3px

ldpi:mdpi:hdpi:xhdpi:xxhdpi=3:4:6:8:12

 

3.單位換算工具類

package com.zzw.Qunyinzghuan3;import android.content.Context;/** * Created by zzw on 2016/7/12. * 描述: */public class DisplayUtil {    /**     * 將PX裝換為dpi或者dp值,保證尺寸大小不變     *     * @param context     * @param pxValue     * @return     */    public static int px2dip(Context context, float pxValue) {        final float scale = context.getResources().getDisplayMetrics().density;        return (int) (pxValue / scale + 0.5f);    }    /**     * 將dip裝換為px,保證尺寸大小不變     *     * @param context     * @param dipValue     * @return     */    public static int dip2px(Context context, float dipValue) {        final float scale = context.getResources().getDisplayMetrics().density;        return (int) (dipValue * scale + 0.5f);    }    /**     * 將px值裝換為sp值,保證文字帶下不變     *     * @param context     * @param pxValue     * @return     */    public static int px2sp(Context context, float pxValue) {        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;        return (int) (pxValue / fontScale + 0.5f);    }    /**     * 將sp值裝換為px值,保證文字帶下不變     *     * @param context     * @param spValue     * @return     */    public static int sp2px(Context context, float spValue) {        final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;        return (int) (spValue * fontScale + 0.5f);    }}
DisplayUtil

系統提供的轉換為px的方法:

  /**     * 將sp值裝換為px值,保證文字帶下不變     *     * @param context     * @param spValue     * @return     */    public static int sp2px(Context context, float spValue) {        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue, context.getResources().getDisplayMetrics());    }    /**     * 將dip裝換為px,保證尺寸大小不變     *     * @param context     * @param dipValue     * @return     */    public static int dip2px(Context context, float dipValue) {        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, context.getResources().getDisplayMetrics());    }
system2px

 

android手機尺寸相關p107-p110

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.