Android Question font size for diffrent varients

adastra

Member
Licensed User
Longtime User
hi
i just want to know to define font size for different size layouts, i have a label and i define size 20 for my tab(7 inch) but when i use it on my mobile(4.5 inch) it is showing to big. how can i adjust it for both layouts. please help.
 

Sanxion

Active Member
Licensed User
Longtime User
The recommended way is to use a single phone sized variant and let AutoScaleAll increase the fonts sizes for larger devices.

You can use anchors and the designer script to change the layout if needed.

Erel - what is supposed to happen when the device is larger - for example 10" - but the resolution is less than the device the app has been developed on? Is the font size supposed to be scaled up with AutoScaleAll on?
 
Upvote 0

adastra

Member
Licensed User
Longtime User
thanks for reply
actually i am creating my layout in coding not in designer so how to use autoscaleall. so i used
lbl.TextSize = lbl.TextSize / access.GetUserFontScale
but it is not working. do't know what to do.
 
Upvote 0

adastra

Member
Licensed User
Longtime User
i can create the layout in designer if it is static. but i am query to server and according to the server return records i create layout so how it is possible to create layout in designer prior to khow how many records server will return
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
i can create the layout in designer if it is static. but i am query to server and according to the server return records i create layout so how it is possible to create layout in designer prior to khow how many records server will return

If the server returns 100 records can you show them in an Activity?
I think you should create a record layout (Designer) and use CustomListView (my answer is too concise, I know, but you can understand me reading about CustomListView).
 
Upvote 0

adastra

Member
Licensed User
Longtime User
my all view adjust there size accourding to layout. there is not problem in that but font goes big in tab and in mobile it shows perfect. so is it possible to adust font size like views in code. i created views using x%,y% positions.
 
Upvote 0

adastra

Member
Licensed User
Longtime User
same i did i define text size=20 but this size is perfect in tab, showing perfect but in mobile it is showing so big. that is the problem
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Setting View.TextSize = 20 sets a constant value, it dosn't adjust automatically to the screen size.
You need to calculate a scaling factor depending on the screen size and calculate the appropriate TextSize value.
You get the approximate screen size with GetDeviceLayoutValues.ApproximateScreenSize.

As a TextSize of 20 for a 7'' screen is OK, you could set the TextSize property like this:
View.TextSize = GetDeviceLayoutValues.ApproximateScreenSize * 2.8
The factor 2.8 is ~20 / 7 but you need to adapt it fore each TextSize value.

You could also calculate a scale factor:
TextScaleFactor = GetDeviceLayoutValues.ApproximateScreenSize / 7
and
View.TextSize = 20 * TextScaleFactor
 
Last edited:
Upvote 0

adastra

Member
Licensed User
Longtime User
thank you , thank you so much, you solved my problem now it is working perfectly on my tab and on my mobile
thank you again
 
Upvote 0
Top