I have an XML that employs the following padding in its layout:
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
where both @dimen/activity_vertical_margin
and @dimen/activity_horizontal_margin
are 14dp
each.
In my Java class, I use a toast to see, at runtime, what the actual margins are:
int vert = (int) getResources().getDimension(R.dimen.activity_vertical_margin);
int horz = (int) getResources().getDimension(R.dimen.activity_horizontal_margin);
Toast.makeText(getApplicationContext(), "vert: " + vert + "\n" + "horz: " + horz, Toast.LENGTH_LONG).show();
I'm testing this on 3 different devices:
For both the Samsung Galaxies, I get a return value for both vert
and horz
as 42. This is true whether the devices are vertical or horizontal. (Why they don't equal 14, I'm not sure, but as long as they're constant, I'm content.)
However, for the XOOM, I get a return value for both vert
and horz
as 14 when the device is vertical. BUT, when I turn it to horizontal, vert
stays at 14 and horz
becomes 128 (nearly 10 times that of its vertical value).
My question is, why is there this automatic change at runtime? There's nothing in the code that references it and makes it change (I know this because the other devices don't have this problem).
Normally, I wouldn't care too much about this, but in this case, it does make my UI look pretty funky. I looked it up but it doesn't sound like anyone else is having the margins change on them at runtime.
There are 2 dimen.xml in every project. first one is in values folder and other one is in values-sw720dp-land. check in values-sw720dp-land/dimen.xml we have
<dimen name="activity_horizontal_margin">128dp</dimen>
As the Motorola XOOM (Android version 4.1.2) is is 720 landscape device it takes dimen value from this value folder