Android Question Set Label Padding automatic+source

ArminKH

Well-Known Member
Hi all
Is there any way to set padding automatic after we set line space?
I want fit text into a label but after set space my calculate is wrong and my text is not seted in label
Tnx
 

ArminKH

Well-Known Member
B4X:
Sub AutoPadding1(ViewName As View,LineSpaceRate)
    Dim HeightOfLine1,HeightOfLine2,HeightOfLine3,HeightOfLine4,NumberOfLine,TopPadding,Dif,TotalSpace As Float
    Dim lbl As Label
        lbl=ViewName
    Dim MeasureHeight As StringUtils
    Dim JavaMeasureHeight=lbl As JavaObject
    Dim jo=lbl As JavaObject
'----------------------------------------------------------------------
        HeightOfLine1=(JavaMeasureHeight.RunMethod("getLineHeight",Null))/LineSpaceRate  'height of one line before set line space
        HeightOfLine2=HeightOfLine1*LineSpaceRate                                         'height of one line after set line space
        Dif=HeightOfLine2-HeightOfLine1                                                  'Difference
      
        HeightOfLine3=JavaMeasureHeight.RunMethod("getLineHeight",Null)                     'height of one line with line space
        HeightOfLine4=(MeasureHeight.MeasureMultilineTextHeight(lbl,lbl.Text))*LineSpaceRate 'height of lines with line space
        NumberOfLine=HeightOfLine4/HeightOfLine3                                         'number of lines
      
        TotalSpace=(NumberOfLine-1)*Dif                                                     'sum of spaces
        TopPadding=TotalSpace+(NumberOfLine*HeightOfLine1)                                 'sum of spaces and lines height - last line space
        TopPadding=(lbl.Height-TopPadding)/2                                             'free space in top and bottom
        jo.RunMethod("setPadding",Array As Object(0,TopPadding,0,0))
End Sub
 
Last edited:
Upvote 0

ArminKH

Well-Known Member
this is my code but not work properly
LineSpaceRate is given scale rate
for line spacing (multiplier)
i set line space in other sub and after resizing text size i want set padding automatically
 
Upvote 0

ArminKH

Well-Known Member
Yes i have not problem with resize
My problem is with line space changing and padding
If line space change then padding changed too
 
Upvote 0

ArminKH

Well-Known Member
2014_09_26_14.46.06.png
 
Upvote 0

ArminKH

Well-Known Member
This is my library sample
in item 3 i set my text size with label width and height
but this line has 0.5 multiplier line space
i want set padding of label automatic to set it into center of label
if i set line space multiplier to 1
all problem fixed and text correctly shown in center
we can solve this issue with padding but users cant change padding in compiled app
i want calculate new top padding value after set line space and set it into my label
 
Upvote 0

ArminKH

Well-Known Member
What exactly are you trying to do? Can you post a screenshot?

This a part of my library
In item 3 the label text size in more than label height and width and with my sub this textsize decresed
 
Upvote 0
Top