Home  >  Q&A  >  body text

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

阿神阿神2715 days ago468

reply all(2)I'll reply

  • PHPz

    PHPz2017-04-17 17:18:40

    0.5 should ensure accuracy after rounding.
    To convert to sp, you can refer to the FONT_SCALE attribute value in Settings.System to make corresponding adjustments.

    reply
    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);  
        }

    reply
    0
  • Cancelreply