How to set unit for Paint.setTextSize()

前端 未结 5 1204
鱼传尺愫
鱼传尺愫 2020-12-01 17:27

Is it possible to change the unit for Paint.setTextSize()? As far as I know, it\'s pixel but I like to set the text size in DIP for multiple screen support.

5条回答
  •  北海茫月
    2020-12-01 18:07

    I know this topic is old and already answered but I would like to also suggest this piece of code:

    int MY_DIP_VALUE = 5; //5dp
    
    int pixel= (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                                  MY_DIP_VALUE, getResources().getDisplayMetrics());
    

提交回复
热议问题