Font Sizes

davidc

New Member
Hi All

I've been using this great tool for a few months now and making good progress, but have come across an odd issue.

I'm developing an app for a screen of size 480x800. When deployed on my HTC desire, a large font size (100dip) is perfectly displayed as I would expect. However, when it's displayed on a tablet with the identical resolution, the font does not resize and instead moves to the top left of a rectangle. The code I'm using to explore this issue is:

canvas1.DrawRect(rectime,Colors.yellow,True,1)
Canvas1.DrawText(left(strTime,2), 17dip, 110dip, Typeface.DEFAULT_BOLD, 80dip, Colors.Blue, "LEFT")
Canvas1.DrawText(":", 160dip, 100dip, Typeface.DEFAULT_BOLD, 80dip, Colors.Blue, "CENTER")
Canvas1.DrawText(right(strTime,3), 173dip, 110dip, typeface.DEFAULT_BOLD, 80dip, Colors.Blue, "LEFT")
activity.Invalidate2(rectime)

As far as I can see, everything is in dip, but even that shouldn't matter as the display resolution is the same between the devices. The sim is OK as well.

Is there a system/device imposed absolute maximum font size or something?

Thanks

David
 

eps

Expert
Licensed User
Longtime User
This will be due to the dpi difference between the two. Ideally when you define graphical items in B4A you need to outline them for all of the resolutions..

i.e. currently you have 1 or 2 defined for 800x480, dpi 240 (with possibly the other "standard" resolution of 320x480 defined as well - these two seem to be standard ones for Android and are usually automatically catered for in B4A).

You need another one defined as 800x480, dpi 160.

Then you need to handle positioning of them, separately.. :)

HTH
 
Upvote 0

eps

Expert
Licensed User
Longtime User
"However, when it's displayed on a tablet with the identical resolution, the font does not resize and instead moves to the top left of a rectangle"

The problem is the display definitions... The Desire is probably 240 dpi, the tablet will be 160dpi. You need to define a display for your app. of 480x800 @160dpi.
 
Upvote 0

davidc

New Member
I see dots before my eyes

OK thanks all, that seems to be it. I now have a couple of layouts and check the "Density" to select which variant to load.

In a nutshell, I can see that positioning and rectangle sizes are fine, because they relate to the grid, which is the same across devices with the same 480x800 resolution. But font sizes seem absolute, so they must be adjusted by the scaling factor. And when you do that, you have to change the size and co-ordinates of of the objects which contain the text.

Thanks!
 
Upvote 0

kickaha

Well-Known Member
Licensed User
Longtime User
I thought (and it seems to work in my apps) that if you define the font size as a value and not in "dips" then the size would be adjusted automatically for different display densities.

I have layouts working across lots of resolutions and densities and the text resizes as appropriate with no intervention from me - perhaps you are overcomplicating things.

Perhaps Erel or agraham can confirm.
 
Upvote 0

davidc

New Member
Hi and thanks again.

In fact in my first try, I had labels with the numbers on (it's a big clock display, by the way) which I created in the designer. I had thought that these would adjust automatically.

Unfortunately, they didn't scale and just jumped to top left.

Now that I'm aware that density matters, I have two 480 x 800 sims, one with 240 and one with 160. The sim accurately reproduces the symptoms described and also shows that the fix should work, although I haven't had a go with a real 160 device yet.

As far as I can see, with fonts, if you specify a height of say 100 (whatever units those are), and these give something which is physically 2cm tall on device 1 (4.3" screen/480/800), then the font will be scaled so that it results in a 2cm height on device 2 (7" screen/480/800). This is consistent with what Erel and agraham point out.

However, there is a difference if you use point values or dip. I suppose I had naively hoped that a font specified as "100dip" would consume the same proportion of the screen on devices with the same pixel dimensions (eg 480 x 800), just as (for example) 240 x 200 rectangle consumes a quarter of the screen in each case. But that's not the case.

Anyway, now that I know about it, I can load layouts according to density and manually tweak the font size and label position on each layout.
 
Upvote 0
Top