使用RelativeSizeSpan与TextView的textAllCaps为true不起作用

所有的标题。

这是一个错误或期望的行为? 而在最后的情况下,我不明白为什么?

可能是一个错误或相互排斥。

当设置textAllCapsTextView应用TransformationMethod ,将文本转换为普通Strings ,使源文本CharSequence消除所有其他样式和跨度。

你可以通过编程来欺骗它(Kotlin天真):

  val text = textView.text // at this point allCaps is applied so text is caps textView.setAllCaps(false) // remove the allCaps val spannable = SpannableString(text) // create new spannable with allCapped text spannable.setSpan(RelativeSizeSpan(1f), 0, text.length, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE) textView.text = spannable //set it. 

另一种方法是创建您自己的TransformationMethod ,它将为每个设置的文本应用Span。