getting the screen density programmatically in android?

后端 未结 19 2956
感动是毒
感动是毒 2020-11-22 01:56

How to get the screen density programmatically in android?

I mean: How to find the screen dpi of the current device?

19条回答
  •  孤独总比滥情好
    2020-11-22 02:27

    This also works:

     getResources().getDisplayMetrics().density;
    

    This will give you:

    0.75 - ldpi

    1.0 - mdpi

    1.5 - hdpi

    2.0 - xhdpi

    3.0 - xxhdpi

    4.0 - xxxhdpi

    enter image description here

    ref: density

    ref 2

提交回复
热议问题