将像素值转换为毫米-Android [英] Converting Pixel values to mm - Android
问题描述
由于特定的需求,在我的android布局中,我使用了"mm"来提供尺寸.同样在TextView中,我以"mm"提供尺寸.当我执行textView.getTextSize()
时,返回的大小始终以像素值表示.我想将该像素值转换为"mm".例如,如果我将字体大小设置为"2mm",那么在任何设备上,当我执行getTextSize()
时,我都希望获得"2mm".
Because of specific needs, in my android layout, I have used "mm" to provide size. In TextView also, I have provided sizes in "mm". When I do textView.getTextSize()
, the size returned is always in pixel values. I want to convert that pixel value in "mm". For example, if I have set font size as "2mm", then on any device, when I do getTextSize()
, I would like to get "2mm".
我应该为此使用任何特定方法吗?我可以找到将"mm"转换为像素"的答案,但是找不到反之亦然的转换方法.
Should I use any specific method for that? I could find answers to convert "mm" to "pixel" but could not find anything about converting vice-versa.
推荐答案
我们使用因此您可以尝试
像素=毫米* metrics.xdpi *(1.0f/25.4f);
Pix = mm * metrics.xdpi * (1.0f/25.4f);
MM = pix/metrics.xdpi * 25.4f;
MM = pix / metrics.xdpi * 25.4f;
这篇关于将像素值转换为毫米-Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!