Automatic text sizes: I need help.

icebold

Member
Licensed User
Longtime User
Hi all,

I'm trying to automatic scale textsizes in every elements I have in my layout but without success :(

I have good result using the following script, found here in the forum:


B4X:
Dim lv As LayoutValues
lv = GetDeviceLayoutValues

Select lv.Scale
Case 2
   devicetype = "Smartphone 5"
   TextSizeRatio = 1.5
Case 1.5
   If lv.Width > 1100 Then
      devicetype = "Tablet 7"
      TextSizeRatio = 2
   Else
      devicetype = "Smartphone 3.5"
      TextSizeRatio = 1
   End If
Case 1
   If lv.Width > 1100 Then
      devicetype = "Tablet 10"
      TextSizeRatio = 3
   Else If lv.Width < 600 Then
      devicetype = "Smartphone 3.5"
      TextSizeRatio=1
   Else
      devicetype = "Tablet 7"
      TextSizeRatio = 2
   End If
End Select

'then TextSizeRatio to my elements, example:
button1.textsize=14*TestSizeRatio

It works with most common phone's densities, properly adapted, but I still don't like results with some devices with "abnormal" densities,
I would like to create a sub that proportionally adapts text sizes for all smartphones.

Do you think it would be possible?

Could anybody suggest me another good solution?

Thanks!

Davide

( I hope my english is not too bad! )
 

icebold

Member
Licensed User
Longtime User
I use a single layout for my project, 320x533 scale 1,
I'm using your designer script for automatically adapt every views such buttons, labels etc. for every devices with values in %, and it works fine.

If in the designer script ( all variants ) I set:
button1.textsize=14
what exactly happens? does Textsizes of this element becomes adapded for every resolutions and densities? I mean, as a button is changing it's position, width and height relative to a new device, it's text content is also proportionally stretched?

I'm actually call a procedure to recalculate new textsizes for every elements, maybe it's not necessary.

It's better to use more layout variants?
( I'll do it for 10" tablets, as you reccomended me )

thanks :)
 
Upvote 0

nfordbscndrd

Well-Known Member
Licensed User
Longtime User
If you have not already looked at the Designer page in the Documentation Wiki, the Introduction has links to 3 screen shots which illustrate the problem of the same layout on different sized devices but with the same density/scale.

Because the scale is the same, the text size does not get adjusted. Since a size 14 will look proportionally smaller on, say, a 1280x800 scale 1 (10" tablet) than on an 800x480 scale 1 (7" tablet), the size must be manually adjusted either in code or by making a separate layout for the different size devices, which is why Erel said to make a layout for tablets.
 
Upvote 0

duneplodder

Active Member
Licensed User
Longtime User
Hi Davide,
As a quick & dirty option could you try something like this in the "all variants script" window of Designer Scripts:

button1.textsize=button1.textsize*(100%x/320)
where the base layout is 320 x 480.

Just a thought.
Robert
 
Upvote 0
Top