Android Phone size related p107-p110

Source: Internet
Author: User

1.LDPI-----240x320-----Density 120

MDPI-----320x480-----Density 160

HDPI-----480x800-----Density 240

XHDPI-----720x1280-----Density 320

XXHDPI-----1080x1920-----Density 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. Unit conversion Tool Class

 Packagecom.zzw.Qunyinzghuan3;ImportAndroid.content.Context;/*** Created by ZZW on 2016/7/12. * Description:*/ Public classDisplayutil {/*** Replace PX with DPI or DP value to ensure size is unchanged * *@paramContext *@paramPxvalue *@return     */     Public Static intPx2dip (Context context,floatpxvalue) {        Final floatScale =context.getresources (). Getdisplaymetrics (). density; return(int) (Pxvalue/scale + 0.5f); }    /*** Change the dip to PX to ensure the size is unchanged * *@paramContext *@paramDipvalue *@return     */     Public Static intDIP2PX (Context context,floatdipvalue) {        Final floatScale =context.getresources (). Getdisplaymetrics (). density; return(int) (Dipvalue * scale + 0.5f); }    /*** Replace the PX value with the SP value to ensure the text is not changed * *@paramContext *@paramPxvalue *@return     */     Public Static intPX2SP (Context context,floatpxvalue) {        Final floatFontscale =context.getresources (). Getdisplaymetrics (). scaleddensity; return(int) (Pxvalue/fontscale + 0.5f); }    /*** Replace the SP value with the PX value to ensure the text is not changed * *@paramContext *@paramSpvalue *@return     */     Public Static intSP2PX (Context context,floatspvalue) {        Final floatFontscale =context.getresources (). Getdisplaymetrics (). scaleddensity; return(int) (Spvalue * Fontscale + 0.5f); }}
Displayutil

The system provides a method for converting to PX:

  /*** Replace the SP value with the PX value to ensure the text is not changed * *@paramContext *@paramSpvalue *@return     */     Public Static intSP2PX (Context context,floatspvalue) {        return(int) typedvalue.applydimension (typedvalue.complex_unit_sp, Spvalue, Context.getresources (). GetDisplayMetrics ()); }    /*** Change the dip to PX to ensure the size is unchanged * *@paramContext *@paramDipvalue *@return     */     Public Static intDIP2PX (Context context,floatdipvalue) {        return(int) typedvalue.applydimension (Typedvalue.complex_unit_dip, Dipvalue, Context.getresources (). GetDisplayMetrics (    )); }
system2px

Android phone size related p107-p110

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.