Textview 사이에 이미지 넣기

나고수·2022년 3월 13일
0

1일1공부

목록 보기
17/67
  val htmlText = Html.fromHtml(
            "텍스트 사이에 <img src=\"drawable 파일 이름(확장자는 필요없음)\">이미지 넣기",
            HtmlCompat.FROM_HTML_MODE_COMPACT,
            ImageGetter(),
            null
        )
       

 binding.textView.text= htmlText       


 inner class ImageGetter : Html.ImageGetter {
 //getDrawable method is called when the HTML parser encounters an <img> tag.
        override fun getDrawable(source: String?): Drawable {
            val resID = this@MainActivity.resources.getIdentifier(
                source,
                "drawable",
                this@MainActivity.packageName
            )
            val d = this@MainActivity.resources.getDrawable(resID, null)
            //drawable 얻기
            d.setBounds(0, 0, d.intrinsicWidth, d.intrinsicHeight) //default width/height of that drawable.
             // 사이즈를 추가하고 싶다면,
            // setBounds 변경하기
            return d
        }
    }
profile
되고싶다

0개의 댓글