Add floating point value to android resources/values -


I want to add lines to lines between my textives using the android: lineSpacingMultiplier Trying the:

Extra spacing between lines of text should be a floating point value such as "1.2", as a multiplier

As I am using some different textview, I want to add a global dimension / value to my resources, but I do not know which tag to use it It is, if it exists, I have tried all those that I understand, but none of these works.

Whatever I have to do, something like this will happen:

  & lt; Resources & gt; & Lt; Dimen name = "text_line_spacing" & gt; 1.4 & lt; / Dimen & gt; & Lt; / Resources & gt; Edit  

Edit: I know about android: lineSpacingExtra (which requires a dimension with an attached unit), but I android I would like to use: linespacing multiplier if possible

is a solution:

  & lt; Resources & gt; & Lt; Item name = "text_line_spacing" format = "float" type = "dimen" & gt; 1.0 & lt; / Item & gt; & Lt; / Resources & gt;  

In this way, your float number will be below @ daemon. Note that you can use other "format" and / or "type" modifiers, where format means:

format = attach attachment type:

  • Integer
  • Integer
  • ...
  • And for this Stands:

    type = resource type (referenced with R.XXXXX.name):

    • Color
    • Slow down
    • < Li> String
    • Style
    • etc ...

    To get resources from the code, you need to use this snippet New:

      typed value out value = new TypedValue (); GetResources () GetValue (R.dimen.text_line_spacing, outValue, true); Float value = outValue.getFloat ();  

    I know that this is confusing (you would expect getResources (like call) GetDimension (R.dimen.text_line_spacing) ), but Android < In addition to this, there is a small "hack" to put float number in dimension, but warning that it actually hacks , And you are giving the opportunity to lose float range and accuracy.

      & lt; Resources & gt; & Lt; Dimen name = "text_line_spacing" & gt; 2.025px & lt; / Dimen & gt; & Lt; / Resources & gt;  

    And with the code, you can get that float from the

      float line spacing = getResources (). GetDimension (R.dimen.text_line_spacing);  

    In this case, the value of linespacing is 2.024993896484375 , and not 2.025 as you would expect < / P>


Comments