持有自定义视图的可跨越文本 [英] Spannable text that holding custom view
问题描述
是否可以将自定义视图添加到可跨文本中?
Is that possible to add a custom view into a spannable text?
在android.text.style
包中我可以看到很多类型的spannable对象,但我想知道我是否可以添加自定义视图.
In android.text.style
package I can see many types of spannable objects, but I wonder if I can add a custom view.
spanable.setSpan(CustomView, .. , .. ,..)
请注意:CustomView 可能是任何类型的视图,即:WebView
Note that: CustomView maybe any sort of view i.e: WebView
推荐答案
所以看起来使用 Spannable 的方式来处理这种情况会很有挑战性.
So looks like it will be challenging to use Spannable way to handle such case.
因此,我创建了一个新库来处理标签,以便我可以在任何我想要的地方使用它们.
Therefore I created a new library to handle tags so I can use them wherever I want.
这是一个例子
HtmlParser.Builder(StringSource(source)).setCallback(object : HtmlParser.ParserCallbacks {
override fun onParseFinished(list: List<Element>) {
list.forEach {
Log.d(TAG, "onParseFinished: ${ElementType.values()[it.type]} ||| ${it.toString()}")
if (it is ImageElement) {
Log.d(TAG, "onImageFound: $it ||| ${it.ImageUrl}")
} else if (it is IFrameElement) {
Log.d(TAG, "onIFrameFound: $it ||| ${it.url}")
} else if (it is BlockQuoteElement) {
Log.d(TAG, "onBlockQuoteFound: ${it.data} ${it.text}")
} else if (it is FigureElement) {
Log.d(TAG, "onFigure: ${it.caption} ${it.url}")
}
}
} override fun onParseError(exception: Exception) {}})
.build()
现在我可以处理任何我想要的元素,即:RecycleView
Now I can handle elements in whatever I want i.e: RecycleView
这篇关于持有自定义视图的可跨越文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!