Android Question MeasureStringWidth - what is the factor?

Discussion in 'Android Questions' started by tdocs2, Feb 23, 2015.

  1. tdocs2

    tdocs2 Well-Known Member Licensed User

    Greetings, all.

    Thank you for your replies.

    In the code below:

    MenuTextSize=CanvasMenu.MeasureStringWidth(MList.Get(i),Typeface.DEFAULT,20'in dpi not dip
    The result is in dpi and not in dip.

    The question is, what factor is used for the computation of width in dpi?

    Is it from xdpi (see ExactSize - code from Erel):

    Sub ExactSize As Double
    Dim r As Reflector
      r.Target = r.GetContext
      r.Target = r.RunMethod(
      r.Target = r.RunMethod(
      xdpi = r.GetField(
      ydpi = r.GetField(
    'Return Sqrt(Power(100%x / xdpi, 2) + Power(100%y / ydpi, 2))
      Return Sqrt((100%x / xdpi)*(100%x / xdpi) + (100%y / ydpi)*(100%y / ydpi))
    End Sub
    or is it from:

    Sub GetDevicePhysicalSize As Float
    lv = 
    Return Sqrt(Power(lv.Height, 2) + Power(lv.Width, 2)) / lv.Scale / 160

    End Sub
    In some cases, the factor is the same, but in the majority of cases (at least, in what I have seen), the xdpi is different than the scale (most of the time smaller).

    Best regards.

    ArminKH likes this.
  2. Erel

    Erel Administrator Staff Member Licensed User

    There is no scaling or factor at all here. It returns the number of pixels.
    ArminKH likes this.
  3. tdocs2

    tdocs2 Well-Known Member Licensed User

    Thank you, Erel.

    Just for clarification - xdpi = pixel?

  4. klaus

    klaus Expert Licensed User

    dpi = dots per inch
    xdpi means x dots per inch horizontally = x pixels per inch horizontally.
    tdocs2 likes this.
  5. tdocs2

    tdocs2 Well-Known Member Licensed User

    Thank you, Klaus.

    I did not properly ask the question, but I received the answer I was looking for. I meant to ask if the pixel is the dot in dpi - and it is.

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice