(一)、EditText文本解析HTML标签加载网络图片展示
1、这个有点尴尬,理解错了需求,最后需求不需要这么做,但研究都研究了,将成果做一下记录
private val options by lazy {
RequestOptions()
.optionalTransform(CircleCrop())
.override(dip(68), dip(68))
.transform(RoundedCorners(dip(10)))
}
binding.etView.setText(Html.fromHtml(stringBuilder.toString(),
{ source ->
val drawable = LevelListDrawable()
GlideApp.with(this@MoodEditActivity)
.asDrawable()
.load(source)
.apply(options)
.into(object : CustomTarget<Drawable>(){
override fun onResourceReady(
resource: Drawable,
transition: Transition<in Drawable>?
) {
drawable.addLevel(1, 1, resource)
drawable.setBounds(0, 0, resource.intrinsicWidth, resource.intrinsicHeight)
drawable.level = 1
binding.etView.invalidate()
binding.etView.setText(binding.etMood.text)
}
override fun onLoadCleared(placeholder: Drawable?) {
}
})
drawable
}, null), TextView.BufferType.SPANNABLE)
主要是使用LevelListDrawable(),在Glide加载成功对设置进去并且刷新。
效果如图: