I have a label which displays a RichString using agraham's library. StrUtil.MeasureMultilineTextHeight is not giving the correct height. Is there a solution using reflection or some other method?
rs.Initialize(File.ReadString(File.DirAssets, CurrentBook & i & ".txt"))
rs = rsf.Format(rs)
Label1.Text = rs
Panel1.AddView(Text, 20dip, 10dip, 100%x - 40dip, 10000)
ScrollView1.Panel.Height = SU.MeasureMultilineTextHeight(Text, rs) + 20dip
Text.RemoveView
ScrollView1.Panel.AddView(Text, 20dip, 10dip, 100%x - 40dip, Panel1.Panel.Height)
After so long, is it possible to get a lable heigh who is RichString formatted?It might be possible to accomplish this with a library. However with reflection it will be too complicated.
#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
Try this inline Java code:
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
public int MeasureMultilineTextHeight(TextView Label) {
public static int MeasureMultilineTextHeight(TextView Label) {