Relative Y Location in Data Field

I found that this seems to place my "value" at the right position in the data field. But this is a poor technique. 13 is an absolute position and probably is not portable across devices with different data field heights. What I really want to for my value to be about the same relative position from the bottom of the data field so it appears similar to the built-in data fields. Like, say, 4 pixels from the bottom. I can't seem to find the method that'll let me do that. Any ideas?


valueView.locY = valueView.locY + 13;
  • If you want it centered in the DF, the simplest way is to get the width and height of the DF (I typically do that in onLayout()), and then draw the text like this:

    dc.drawText(width/2,height/2,font,"string",Gfx.TEXT_CENTER|Gfx.TEXT_VCENTER);

    If you have your own field that spans y and y2, do the same basic thing:
    dc.drawText(width/2,y+((y2-y)/2),.......

    If you have something like 2 lines you want to display, you can also use something like dc.getFontHeight() to space things.