As mentioned in title align center does't work for image span for two line text. I want to show click able icon at the end of text and want it to be center aligned to the last line text but it works on all phones except chinese brand mi 8 lite. Here is the code:
val s = "Some text here "
val builder = SpannableStringBuilder(s)
val drawable = ContextCompat.getDrawable(requireContext(), R.drawable.ic_info) as Drawable
drawable.apply {
setBounds(0, 0, intrinsicWidth, intrinsicHeight)
}
builder.setSpan(ImageSpan(drawable, if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) ImageSpan.ALIGN_CENTER else ImageSpan.ALIGN_BOTTOM),s.length-1,s.length, Spannable.SPAN_EXCLUSIVE_INCLUSIVE)
Here is the screenshot POV where icon gets merged with in text attached below
I had the same problem, but with Android 10 (I didn't test with mi 8 lite). I just changed ImageSpan.ALIGN_CENTER by ImageSpan.ALIGN_BOTTOM or ImageSpan.ALIGN_BASELINE depending on which you prefer. Hope it helps !