Android Question Scaling text size defined as a property in CustomView

Alessandro71

Well-Known Member
Licensed User
Longtime User
AutoScaleAll works fine for text field defined in the designer, but I have a CustomView class, with multiple text fields, where the text size is defined by an Int property field.
How can I apply the same scaling factor to this parameter?
Is there a way to recover the factor used by the designer and then multiply the property value?
 

LucaMs

Expert
Licensed User
Longtime User
where the text size is defined by an Int property field.
Int as Integer or typo? TextSize must be set as Float!


Recently I think I saw code suggested by Erel precisely for this... but I also remember not having found it anymore

In my opinion, a good method is to load an invisible EditText from a layout and calculate for yourself what was the scaling factor between the TextSize set in the Designer and the resulting one at runtime.

You can still remove the invisible EditText afterwards, although it is not necessary.
 
Last edited:
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
Yes I mean Integer
I used Integer because the standard label text size box in the designed works with integers as well.
I expect to convert to float after scaling and before assigning to actual text field.
I will try the "ghost label" trick to recoved the scaling factor, but I might guess there's a more direct approach.
 
Upvote 0

Alessandro71

Well-Known Member
Licensed User
Longtime User
as a followup, I set the text size of the base label to 1, and used that as a multiplication factor for my text size
not elegant enough, since the base label text size must be to 1 and it's not really intuitive
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…