Issue
Here is my attempted code.
val imageView = ImageView(holder.itemView.context)
holder.itemView.textView.setCompoundDrawablesWithIntrinsicBounds(
GlideApp.with(holder.itemView.context).load(URL).into(imageView), 0, 0, 0)
I am also not sure about Glide's image target. I have it set as .into(imageView)
. Since I want to add an image with TextView, there is no ImageView initialized to load the URL image into. My thought was to create one programmatically with
val imageView = ImageView(holder.itemView.context)
An error that I see is that GlideApp.with(holder.itemView.context).load(URL).into(imageView)
is not being detected as a drawable.
Solution
In Kotlin you can do as :
Glide.with(context).load("url").apply(RequestOptions().fitCenter()).into(
object : CustomTarget<Drawable>(50,50){
override fun onLoadCleared(placeholder: Drawable?) {
textView.setCompoundDrawablesWithIntrinsicBounds(placeholder, null, null, null)
}
override fun onResourceReady(
resource: Drawable,
transition: Transition<in Drawable>?
) {
textView.setCompoundDrawablesWithIntrinsicBounds(resource, null, null, null)
}
}
)
Answered By - Alok Mishra
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.