Android Question multiline Label with CSBuilder and correct Label.Height

peacemaker

Expert
Licensed User
Longtime User
HI, All

Please, suggest, how can it be made.
If it needs to have:
1) multiline text block (variable lines qty !!!)
2) each text line is with various formatting with help of CSbuilder: bold, alignments... - so not plain text
3) and main: spacing between lines are needed also customizable (for ex. by CSbuilder.Size(X).Append(CRLF))

So, when the text is generated - the total block height is unknown and need to calculate it to make correct padding inside the block also.

As text size is various of lines, and space between - StringUtils.MeasureMultilineTextHeight gives variable height for the single fixed TextSize - it's the problem.

Do we have any solution for such "rich text" block ? With correct height calculation, if any vertical part is variable.
 
Last edited:

Emme Developer

Well-Known Member
Licensed User
Longtime User
Try this

B4X:
#if JAVA

import android.text.StaticLayout;
import android.text.Layout.Alignment;
import android.widget.TextView;
public int MeasureMultilineTextHeight(TextView Label) {
    StaticLayout sl = new StaticLayout(Label.getText(), Label.getPaint(),
          Label.getLayoutParams().width - Label.getPaddingLeft() - Label.getPaddingRight(),
    Alignment.ALIGN_NORMAL, 1, 0 , true);
    return sl.getLineTop(sl.getLineCount());
    }
#end if
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
But StringUtils.MeasureMultilineTextHeight maybe the same ?

Seems, it needs some function to print the Label on a canvas to get the real height of any lines + spaces set ...
 
Last edited:
Upvote 0
Top