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);
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);
and you can notice from the first image below, this is also incorrect(it is not possible the screen width to be 76 mm) .
Image of Samsung Galaxy Stratosphere 2(THIS IS INCORRECT) and Image of Samsung Galaxy S4(THIS IS CORRECT)
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