Text sizes in different layouts

GTBecker

Member
Licensed User
Longtime User
Long-time programmer, new to b4A, and I'm puzzled.

I've written a simple display of random values in Designer-defined labels, with four layout variants - two orientations each for 1200x800 and 960x540.

I am surprised to find that the text size, last-defined in any of the four layouts, is shared with all layouts. That is, the text is either too large or too small for all but one layout.

I must be missing something. How can I define a particular text size for each layout? Or do I need to actively change the text size in code?

Tom
 

Kevin

Well-Known Member
Licensed User
Longtime User
Fonts, resolutions and variants... One of the biggest things that is taking me forever to fully grasp! :D

I guess you just leave it alone, but I've read differing opinions on this and other layout type things. Or I never really got an answer that spelled it out for my simple mind. :D

Basic4android Search: Font size
 
Upvote 0

devlei

Active Member
Licensed User
Longtime User
Tom,

I had similar problems getting the text sizes to be correct for my ListViews on different screen sizes and resolutions. There seem to be quite a lot of options out there, but the one I have used is to use relative (%X & %Y) values for sizing and positioning Views (controls). However, that does not automatically adjust the text sizes, so I used a simple procedure to do this.

The example in the link below is applicable for ListView text sizes, but it should put you on the right track for EditText's.
http://www.b4x.com/forum/basic4andr...listview-textsize-item-heights.html#post77743
 
Upvote 0

GTBecker

Member
Licensed User
Longtime User
Thanks, gentlemen. I think I see that the issue is perhaps philosophical.

Erel makes it clear that text size of a particular view should be physically the same across variants, presumably for common readability, practical button ergonomics, etc. That would make sense.

What puzzles me still, though, is that I can define a panel or ImageView shape and size that is unique to a variant, but the text placed in that panel cannot be unique, unless it is calculated and set in code. Is that right?
 
Upvote 0

GTBecker

Member
Licensed User
Longtime User
I've taken the approach of loading different layout files for different target machines; each layout has two variants for orientation. That allows me to use common view names and, thus, the same code to work with them - and to use different font sizes in them. I currently have just two target machines, a Xoom (1280x800 physical), and a Bionic (960x540). I select the appropriate layout file with the current Activity.Width, i.e. a width of 1280 or 800 selects the Xoom layout, and 960 or 540 width selects a layout for the Bionic. That works and I can progress.

Is the variant selection process documented? If there are, for example, four similar custom variants defined, how does the OS determine the most suitable? Is there a maximum number of variants that can be defined? I've experimentally defined 20 variants, which appears to misbehave; is that too many?
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Note that you are missing the most important value in these resolutions which is the scale value.
There is no limit to the number of variants. Though I don't recommend you to make 20 variants as it will make your program much harder to maintain.

The selection algorithm uses several measurement to find the "closest" variant.
It checks the normalized width and height and the scale. It prefers layouts that are smaller in size than layouts that are larger than the screen.

If you think that it selects the wrong one then please upload this file with the target details.
 
Upvote 0
Top