I use StaticLayout to handle my text, then showed in TextView.But when i call getHeight of StaticLayout to get handled text height, it is less than the textview's true height. below is core code:
private fun createStaticLayout(text: SpannableStringBuilder): StaticLayout {
val width = measuredWidth - paddingLeft - paddingRight
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
StaticLayout.Builder.obtain(text, 0, text.length, paint, width)
.setAlignment(Layout.Alignment.ALIGN_NORMAL)
.setIncludePad(includeFontPadding)
.setLineSpacing(lineSpacingExtra, lineSpacingMultiplier)
.build()
} else {
StaticLayout(
text,
paint,
width,
Layout.Alignment.ALIGN_NORMAL,
lineSpacingMultiplier,
lineSpacingExtra,
includeFontPadding
)
}
}
text = tempText2
layoutParams.height = tempLayout.height + paddingTop + paddingBottom
requestLayout()
and this is log info:
staticLayoutHeight -> 237
lineHeight -> 46
textViewheight -> 277
textSize -> 39.0
destiny -> 2.625