[android-developers] Question about using dimension resources in other resources vs. in Java code
I'm just reading about dimension resources (Pro Android 4), and it seems curious how dimension resources are referenced in Java code (at least as specified in this book). The resource value consists of the value and the dimension, like 5px or 5dp or 5sp. You could reference this in a layout resource, like to set the textSize of a TextView. My assumption is that the unit specified in the dimension would be used in that calculation, which would result in slightly different sizes for the previous examples. That is only an assumption. It seems reasonable. What would be the point of specifying the unit if it isn't used anywhere? In Java code, however, it appears that you reference a dimension resource like this: float dimen = activity.getResources().getDimension(R.dimen.mysize_in_pixels); That looks to me like it's only returning the dimensionless value (5, for instance). -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Question about using dimension resources in other resources vs. in Java code
The return value is in pixels, converted from whatever value in the dimen... resource based on current display metrics. There are three versions of getDimension, differing in rounding rules. http://developer.android.com/reference/android/content/res/Resources.html#getDimension(int) http://developer.android.com/reference/android/content/res/Resources.html#getDimension%28int%29 -- K 17.03.2012 21:23, David Karr ?: In Java code, however, it appears that you reference a dimension resource like this: float dimen = activity.getResources().getDimension(R.dimen.mysize_in_pixels); That looks to me like it's only returning the dimensionless value (5, for instance). -- Kostya Vasilyev -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en