Maison  >  Questions et réponses  >  le corps du texte

android - dp转换为px 和 sp转换为px

阿神阿神2715 Il y a quelques jours464

répondre à tous(2)je répondrai

  • PHPz

    PHPz2017-04-17 17:18:40

    0.5应该是保证四舍五入后的精确度。
    转sp可以参考Settings.System中的FONT_SCALE属性值来做对应调整。

    répondre
    0
  • 迷茫

    迷茫2017-04-17 17:18:40

    public static int sp2px(Context context, float spValue) {  
            final float scale = context.getResources().getDisplayMetrics().scaledDensity;  
            return (int) (spValue * scale + 0.5f);  
        }

    répondre
    0
  • Annulerrépondre