B4A Library SmartString(Auto adjusting text size)

Smart String is no longer supported, please check out T8TextSize lib

Hello every one


This library is for adjusting the text size automatically or manual with the following features:


This sub tries to increase or decrease the single line text size and preserve the aspect ratio as Long As the height of the text Is Not greater than the height of the view.in other word you can increase your text size until you have space in width and height,and the text will be single line always and your aspect ratio is always preserved(IT’S ACCURACY IS ACCEPTABLE BUT IS NOT 100%)

NOTE1: The text size can not be changed with every 1dip

NOTE2: Your text in base layout should not be larger than 1 line


This sub tries to fit your text in the view and then set maximum size if you have space in width and height of the view.and it’s always will be one line.this sub is similar to singleline1 but with two difference

1-Aspect ratio was not preserved and text can fit in the view

2-your text in base layout can be longer than one line but after set singleline2 it will be 1 line


This sub increase or decrease your text size as long as you have space in width and height and number of lines is smaller than your given maximum lines number


This sub increase or decrease your text size as long as you have space in width and height this sub not related to number of lines

NOTE: This sub has an argument named CanBeLarger.by using this option you can have more control over the size of your text if it’s not be larger than view spaces then the text size will not be increased.in other word this option is useful when you want to keep your base text size in larger devices


with this sub you can give a scale rate for base layout and then your text size will be larger in large devices and be smaller in small devices with your given scale rate.

NOTE:This sub don’t preserve your aspect ratio and not depended on available spaces in width or height in other word you are free to do what do you want


With this sub You can Set any changes on a view and apply that textsize and font to same viewes with same height and width

This option is for decrease cpu , ram , battery usage with reduce calculates


Set your text to given line number without any change in text size


This library is a collection of tools for strings
and you can ellipsize(cut) your text or set spaces between lines or fit the text in every position that you want Such as top or center

9.RichString1 – 4

This sub help you to use richstring library simpler with just call this subs

IMPORTANT NOTE1: If you use multiline1 or multiline2 and set your line space larger or smaller than default.your text size will be adapted but the position of text in your view will not be able to auto padding but you can set it manualy with SetPadding sub.this issue may be solved in next update

IMPORTANT NOTE2:Please don’t use this automatic text size library for adjust every text in your activity

Because this library adjusting text size with calculate and can be a reason for decrease free ram.In other word if you use this sub too much and always then maybe your ram free space decreased or cpu usage be high in weak devices

You have two solutions for solve this problem:

1-you can use SameStyle sub for decrease calculates

2-or Use activity first time option I think


This is my first library and may have many bug.please help and report any bug to solve it in next updates

*Required Libraries:
Java object , StringUtils ,RichString

Update 1.1:Fixed an issue with singleline2 and post updated
Update 1.2:Fixed an issue with B4A 4.30


  • SmartString1.1+sample.zip
    207.8 KB · Views: 473
  • SmartString1.2+Sample.zip
    68.9 KB · Views: 576
Last edited:


Well-Known Member
Hi, thanks for the library.

I have tried this library, but stuck when using smartstring singleline2 in my class.

My codes is something like this

SingleLine2 need an activity but there is no activity in MyClass. Is there a solution for this?
i know this,and u can't use this lib in class module directly
i will fix this in next update
but for now maybe u can use callsub to call this sub which is in an activity module


Well-Known Member
Dear arminkh,

Just realized, if this library could use in class module directly, it will make flexible class table more customizable (https://www.b4x.com/android/forum/threads/class-flexible-table.30649/#content)

I imagine that this library could use for column title and auto fit text in table's cell.
This library will be updated
U can download new version sunday
And also if every body has a suggestion or need some possiblity can write here,i will add to this lib