gpt4 book ai didi

android - 在多行 TextView 的末尾放置一个 View

转载 作者:行者123 更新时间:2023-12-04 09:18:57 27 4
gpt4 key购买 nike

我想在动态 TextView 的末尾添加一个自定义 View (一个包含文本和图标的 View ),如图中所示。

提前致谢。

enter image description here

最佳答案

以编程方式是可能的:

fun TextView.setIconifiedText(text: String, @DrawableRes iconResId: Int) {
SpannableStringBuilder("$text#").apply {
setSpan(
ImageSpan(context, iconResId, DynamicDrawableSpan.ALIGN_BOTTOM),
text.length,
text.length + 1,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
}.let {
setText(it)
}
}
textView.setIconifiedText(
"First line text that is longer.\nSecond line text.",
R.drawable.ic_android_black_24dp
)

结果:

关于android - 在多行 TextView 的末尾放置一个 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63130800/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com