Android用Kotlin语言设置 TextView中图文混合排列

1.设置需要显示的文字和图片:

var s:String = "haha"+ ""

2.获取ImageGetter

fun getImageGetter():Html.ImageGetter{
        var imgGetter:Html.ImageGetter =object: Html.ImageGetter {
            override fun getDrawable(p0: String): Drawable {
                var fontH:Int = (resources.getDimension(R.dimen.login_textSize14)*1.5).toInt()
                var id = Integer.parseInt(p0)
                var d:Drawable = resources.getDrawable(id)
                var height:Int = fontH
                var width:Int = (( d.getIntrinsicWidth().toFloat() / d
                        .getIntrins
et_account.setText(Html.fromHtml(s, getImageGetter(),null))

icHeight().toFloat()) * fontH).toInt() if (width == 0) { width = d.getIntrinsicWidth() } d.setBounds(0, 0, width, height) return d } } return imgGetter }
 
  

 
  


3.将内容显示在TextView中

et_account.setText(Html.fromHtml(s, getImageGetter(),null))




你可能感兴趣的:(Android开发中遇到的问题)