Android Question Scale text sizes and alignment

alexanderjames

Member
Licensed User
Longtime User
Hi All

I've got my layout designed using the designer, and then using the designer scripts feature I have set all the views so that it works on all the devices in the UI cloud. So far so good, I was wondering if I have to scale the text sizes and alignments as well ? currently I have this piece of code at the top of my designer script.

AutoScaleRate(0.5)
AutoScaleAll
'###Set the font sizes
txtPassword.TextSize = 40
cmdInput7.TextSize = 30
cmdInput8.TextSize = 30
cmdInput9.TextSize = 30
cmdInput4.TextSize = 30
cmdInput5.TextSize = 30
cmdInput6.TextSize = 30
cmdInput1.TextSize = 30
cmdInput2.TextSize = 30
cmdInput3.TextSize = 30
cmdInput0.TextSize = 30
cmdClear.TextSize = 26
cmdOk.TextSize = 26
lblVersion.TextSize = 14
lblMessage.TextSize = 22
lblConnection.TextSize = 14
cmdExit.TextSize = 22


The text size looks right on the large screen sizes but as you get down to the smaller screens the text is too big and it is no longer in the middle of the button but rather at the bottom of the button and cut off. Am I doing this correctly or is there a better way ?

Many thanks in advance for any assistance and advice.
AJ
 
U

unba1300

Guest
Hi. This is what I do in the Designer Scripts and it works for me:
B4X:
'All variants script

delta = ((100%x + 100%y) / (320dip + 480dip) - 1)
rate = 0.5 'value between 0 to 1.
scale = 1 + rate * delta

btn1.TextSize = btn1.TextSize * scale
'do above for each View that has text.
Hope this is helpful.
 
Upvote 0

devlei

Active Member
Licensed User
Longtime User
I am getting a similar problem to alexanderjames, except that the chopping off of text at the bottom occurs only with certain of the bigger (10") tablets, the Samsung Note 10" being one of them. For example, Buttons have height of 35dip and text size is 16, but they are displayed near the bottom of the button with some being chopped off.

These settings work very well with smaller devices, and I don't want to increase the height as it is unnecessary on smaller devices.

Any suggestions?
 
Upvote 0

devlei

Active Member
Licensed User
Longtime User
Views are set in Designer Script (buttons - 40dip), text size also set in Designer (buttons - Default Bold 16).

Maybe I should ask the question this way:
It seems the Autoscale is adjusting everything too much and making the Text Size too big for the height in the case of bigger tablets.
Would it be better to use a higher AutoScale Rate or a lower one?
Could it just be that certain devices have a greater border between text and edge of button? If so, can this be changed?
 
Upvote 0

devlei

Active Member
Licensed User
Longtime User
Thanks for your willingness to help, Klaus. Sorry for the lack of clarity in my questions.
After much testing, I have reached a solution that seems to be working on a wide range of devices:
When using a dip value for height of views (so that they are never too small on small devices), make sure the AutoScaleRate is close to 0, otherwise the text might not display properly on large (10") devices.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I still don't understand what you are doing !?
If you set AutoScaleRate to 0, don't use it, 0 is equivalent to NO scaling.
Where and how are you using dip values.
If you AutoScaleAll and tafterwards you set Heights with dip values you have the risc to downsize the Heights but not the TextSizes on big screens.
But, as you don't want to tell us what you do and how we are turning in circle.
 
Upvote 0

devlei

Active Member
Licensed User
Longtime User
My apologies - I just never got the chance yesterday to make a small project to demonstrate the issue. I have done so now.

You, however, hit the nail on the head with your one sentence, cause that is exactly what I was doing wrong:
If you AutoScaleAll and tafterwards you set Heights with dip values you have the risc to downsize the Heights but not the TextSizes on big screens.

Correct me if I'm wrong, but I thought to try one of the following options:
  • Set the heights in dip values before the AutoScale in the All Variants section
  • Put the AutoScale right at the end of each variant specific script
  • Set the height in the 'Common Properties' section of 'Main' tab. Are those values in dip?
Thank you for all your help?
 

Attachments

  • TestingAutoScale.zip
    9.2 KB · Views: 155
Upvote 0

klaus

Expert
Licensed User
Longtime User
Attached you find a modified version.
The only constraints are btnD1.Top and bntD1.Height must have the right values for the standard screen. These properties are scaled with AutoScale and then used as reference for all the other views scaling.

As in your test project the only difference between portrait and landscape is the height of all the views, I calculate the height for landscape.
All is done in the All variants script and I've removed the landscape variant.
I use variables in the DesignerScripts it makes any modification much easier.
 

Attachments

  • TestingAutoScale_1.zip
    8.9 KB · Views: 164
Upvote 0

devlei

Active Member
Licensed User
Longtime User
Thank you so much, Klaus!!

I obviously never read the AutoScale tutorial carefully enough as I did not realise one could use variables and If statements in the Designer Script. So the variables are not declared, just used.

Your example really helps to see how to simplify things!!!
 
Upvote 0

devlei

Active Member
Licensed User
Longtime User
One last quick Question:
Does AutoScale in DesignerScript also scale variables? For example:
B4X:
Height = 45dip
Space = 5dip
AutoScaleAll
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
No.
If you want to use variables which should be scaled take the values from a property of a view.
That's the reason why I used in your example:
B4X:
AutoScaleAll
Height = btnD1.Height
Space = btnD1.Top
Both properties are scaled by AutoScaleAll and then I define the variables.
 
Upvote 0
Top