B4A Library [custom view] AutoTextSizeLabel

Status
Not open for further replies.
When you set the text of this custom label the text size is automatically modified to the largest possible size so that all the text is visible.

SS-2013-06-30_11.49.54.png


To use this view in your project, you should take the AutoTextSizeLabel class from the attached example and add it to your project. You should then add a Custom View with the designer and set its type to this class.

The following libraries are required:
- JavaObject
- StringUtils
 

Attachments

  • AutoTextSizeLabel.zip
    8.5 KB · Views: 2,197
Last edited:

metrick

Active Member
Licensed User
Longtime User
How can I change the color of the text on AutoTextSizeLabel? I can change text color in the designer but not with the code, only text option available.
 

LucaMs

Expert
Licensed User
Longtime User
I should add "nuisance" to my signature, I know.
I ask you to forgive me in advance :)

A text could be right-aligned or centered!


Now I'm not particularly bright, but maybe for the right alignment, you should fill in the spaces on the left, do an early check ... Well, I should think.

Sorry
 

Shadow&Max

Active Member
Licensed User
Longtime User
Erel... Can this lib actually break the text up into lines of fitting text? I can't seem to get a long line of text to be formatted throughout the label... it fits it horizontally with tiny fonts, but it's all on one line.

What I'd like to do it set a label to be full screen, pass it a long set of text, and have the lib fit it into the label, spaced out horizontally as well as vertically with the appropriate breaks (I don't want to put the breaks into the text myself as it'll vary).

For example... Full Screen Label... Text is: "This is the time for all good men to come to the aid of their country". Result would be a full screen of text, broken into lines and filling the screen.

Is this possible?
 

Shadow&Max

Active Member
Licensed User
Longtime User
Thank you again Klaus... That was perfect and exactly what I was looking for!
 

chrjak

Active Member
Licensed User
Longtime User
It broke my project... and mlbl didn't work...

But thanks for the example code! I used it to built it in a normal label!

Regards
 

Shadow&Max

Active Member
Licensed User
Longtime User
In what way did it "break your project?" Working just fine for me!
 

chrjak

Active Member
Licensed User
Longtime User
When i inserted it nothing worked any more. (That's normal) But after I changed everything to customview1.mlbl.??? all crashed... (I am changing type face, colors, size and many many things)

anyway. But sadly my Code does not work fine.... And I don't find the mistake...

I call the sub everytime and label1.text is everytime only one line... but sometimes it breaks the text. even if there is no height space for that...
Code:
B4X:
Sub scalelbl1
    Dim bmp As Bitmap
    bmp.InitializeMutable(1dip,1dip)
    cv.Initialize2(bmp)
    Dim size As Float
    For size = 2 To 80
        If CheckSize(size) Then ToastMessageShow("Exit!", True)
    Next
    size = size - 0.5
    If CheckSize(size) Then size = size - 0.5
    Label1.TextSize = size
End Sub

Sub CheckSize(size As Float) As Boolean
        Return cv.MeasureStringWidth(Label1.Text, Label1.Typeface, size) > Label1.Width OR _
            suu.MeasureMultilineTextHeight(Label1, Label1.Text) > Label1.Height
End Sub
 

chrjak

Active Member
Licensed User
Longtime User
Could someone help me, please? I don't get the mistake! Btw. I removed the toastmessage

*Push* :D
 

chrjak

Active Member
Licensed User
Longtime User
like i said there is no error. it's is only shown wrong

When the text is too long then it breaks the line and shows the rest in the second line (see my code)
but the second line is not high enough. so it does not show it correctly...
 

Shadow&Max

Active Member
Licensed User
Longtime User
Add a CRLF to the end of the text.
 

chrjak

Active Member
Licensed User
Longtime User
doesn't help

and sometimes is the size 1.
so there is something wrong...
 

chrjak

Active Member
Licensed User
Longtime User
Like I said above I can't use it because i have to change so many label values, which are not available for customviews...
additionally the label in the class doesn't work either... :/
 
Status
Not open for further replies.
Top