Android - pixels to dips

后端 未结 4 1936
我寻月下人不归
我寻月下人不归 2020-12-10 08:07

I have an image of a face (250px X 250px) that is in an absolute layout element. I currently get the user\'s touch coordinates and using some maths calculate what has been t

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-10 09:14

    public int getDip(int pixel)
    {
            float scale = getBaseContext().getResources().getDisplayMetrics().density;
            return (int) (pixel * scale + 0.5f);
     }
    

提交回复
热议问题