Android XML defined dimension value yielding unexpected results -
I have defined a DP dimension in your XML file like:
& lt; ? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Resources & gt; & Lt; Dimen name = "custom_button_Margin" & gt; 10dp & lt; / Dimen & gt; & Lt; / Resources & gt; The idea is that I use these values to set padding between elements. It works fine when I use the value in my layout XML file
snippet:.
& lt; RelativeLayout android: id = "@ + id / mainButtons" Android: Layout_width = "Fill_parent" Android: Layout_height = "Fill_parent" Android: layout_weight = "0.4" Android: layout_margin = "5dp" android: gravity = "true | Down" & Gt; & Lt; Android: Layout = "@ + id / _7" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" android: text = "@ string / seven" Android: background = "@ drawable / custom_button" Android: Typeface = "monospace" Android: textSize = "@ Dimen / custom_button_TextSize" Android: layout_marginRight = "@ Dimen / custom_button_Margin" Android: layout_marginBottom = "@ Dimen / custom_button_Margin" / & gt; & Lt; / RelativeLayout & gt; The problem occurs when I try to get this value programmatically. I look forward to getting a price that is scaled to match the screen density. Then I'll do, the formula looks (p dp units to convert the pixel units
I've wrapped the thread that function which value receives ... file is defined, and pixels that measure
personal integer get_custom_button_PadV () {final float scale = getResources () getDisplayMetrics () density; return (int) ( RDMmen Custom_button_margin * scale + 0.5F);} When I give code Can I see the following values
scale = 1.0 R.dimen.custom_button_Margin = +21310 99 650 I do not understand the value of Kstm_btn_margin so Why is it big ... I hope that with a scale of 1.0, this will be the value of 10. What am I missing?
You are using Dimension Id as the dimension value. Try it instead:
private int get_custom_button_PadV () {last resource res = getResources ( ); Last float scale = res.getDisplayMetrics (). Density; Return (Int.) (Reset Diemnation (RDIMMAN Cute_Button_Margin) * Scale + 0.5F); }
Comments
Post a Comment