/设置的角度固定的宽度尺寸与PT /毫米ANDROID [英] Setting fixed width size of view with pt/mm/in ANDROID

查看:344
本文介绍了/设置的角度固定的宽度尺寸与PT /毫米ANDROID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图修复的宽度设置为一个观点。 中,毫米和PT密度是独立的,每一个设备上的相同尺寸或​​我错了?
我的看法宽度应141.3pt /49.8毫米,所以我在XML设定Android:layout_width =141.3pt或者通过code:

I'm trying to set fix width to a view. "in", "mm", and "pt" are density independent and the same size on every device or i am wrong? My view width should be 141.3pt/49.8mm , so i am setting in the XML android:layout_width="141.3pt" or via code:

float requiredPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PT, (float) 141.3, dm);
ViewGroup.LayoutParams params = mRequiredSizeLine.getLayoutParams();
        params.width = (int)requiredPx;
        mRequiredSizeLine.setLayoutParams(params);

事情是这样的,这是确定在某些设备(在多数人身上),但例如在三星Galaxy平流层二是不正常。
另外我有一个计算并毫米屏幕显示宽度的方法

The thing is that, this is ok on some devices(on most of them) but for example on Samsung Galaxy Stratosphere 2 it is not ok. Also i have a method that calculate screen display width in in and mm

private double checkDeviceWidthInInches(){
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    double x = Math.pow(dm.widthPixels/dm.xdpi,2);
    double y = Math.pow(dm.heightPixels/dm.ydpi,2);

    return Math.sqrt(x);

和可以从下面的第一图像发现,这也是不正确的(这是不可能的屏幕宽度为76mm)的

and you can notice from the first image below, this is also incorrect(it is not possible the screen width to be 76 mm) .

三星Galaxy平流层2 的图像(这是错误的)和的三星Galaxy S4 的图像(这是正确的)

Image of Samsung Galaxy Stratosphere 2(THIS IS INCORRECT) and Image of Samsung Galaxy S4(THIS IS CORRECT)

所以,你有什么感想?可能有一些问题与设备或?链接设备规范
http://www.samsung.com/us/mobile/cell-phones / SCH-I415SAAVZW

So what do you think? Could be some problem with the device or ? Link for device spec http://www.samsung.com/us/mobile/cell-phones/SCH-I415SAAVZW

任何建议?
谢谢

Any suggestion? Thanks

推荐答案

您应该始终使用DP(密度独立像素)你的视图尺寸。避免使用其他单位。当你想指定大小的文本使用SP单元。 <一href=\"http://stackoverflow.com/questions/2025282/difference-between-px-dp-dip-and-sp-in-android\">Difference PX,DP,倾角和SP在Android中之间

You should always specify dimensions of your views in dp (density-independent pixels). Avoid using other units. When you want to specify a size of text use sp units. Difference between px, dp, dip and sp in Android

这篇关于/设置的角度固定的宽度尺寸与PT /毫米ANDROID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆