Android: 'dp' to 'px' conversion?

前端 未结 4 1396
失恋的感觉
失恋的感觉 2021-02-13 20:47

I am reading this article: http://developer.android.com/guide/practices/screens_support.html

It says that the formula Android uses to convert between a dp

4条回答
  •  名媛妹妹
    2021-02-13 21:25

    I think that would be the best solution 'cause it is standard method:

    int valueInPx= (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_PX, valueInDp, getResources().getDisplayMetrics());

提交回复
热议问题