Solution 1 :
simply: you can’t.
in posted example you aren’t adding ImageView
, you are adding ImageSpan
with just drawable
, thats very not the same…
View
s can’t hold/host other View
s, you have to use ViewGroup
or some subclass
easiest way would be to make some LinearLayout
with vertical orientation and two View
s: TextView
and your custom View
. second one may have android:visibility="gone"
and you can show it only when needed
Problem :
I am trying to add a custom view (the portion with red boundary will be replaced with my custom view having a 3 dots loader animation) at the end of a multi-line TextView
in my Android app.
I know how to specifically add an ImageView
using a SpannableString
like this:-
fun addImageToEndOfTheString(text: String, drawableResourceId : Int ,context: Context) : SpannableStringBuilder {
val drawable = ContextCompat.getDrawable(context, drawableResourceId)!!
drawable.setBounds(0, 0, 98, 50)
val rocketImageSpan = ImageSpan(drawable, ImageSpan.ALIGN_BASELINE)
val ssBuilder = SpannableStringBuilder(text)
ssBuilder.setSpan(
rocketImageSpan,
text.length-1,
text.length,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
return ssBuilder
}
But the problem is I have a custom view which I want to place at the end of my TextView
. How can I achieve that?
Note : My custom view is a subclass of View
.
Comments
Comment posted by Rohit Singla
but the problem will be my
Comment posted by convert your
hard, but “proper” way – your