Reputation: 1018
I want to add a custom view (a view with both text and icon) at the end of dynamic TextView
like in this picture.
Thanks in advance.
Upvotes: 4
Views: 1447
Reputation: 47
Place both of them in relative layout and add this
android:layout_toEndOf="<id of first view>"
to the custom view
Upvotes: -3
Reputation: 22832
It is possible programmatically:
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
)
Upvotes: 8