Images in TextView

1) How can I change / extend the TextView to render inline images?

It seems that setText (Html.fromHtml (... image tags ...)) may actually allow image insertion if configured correctly, but I haven't tried it myself. Even if I still need fine-grained control over the graphic pattern (my ultimate goal is to display embedded animated emoticons). Therefore, unfortunately, a view based on WebKit or the like is also not an option.

2) As an alternative solution, I thought about mixing TextViews and ImageViews (or, more specifically, my subclasses that allow animation), but I'm not sure how I could get the proper packaging (I'm pretty new to Android).

+3
source share
2 answers

this tutorial should help you: http://techdroid.kbeanie.com/2010/06/textview-with-html-content.html

in particular, this section of the tutorial ...

static ImageGetter imgGetter = new Html.ImageGetter() {
             @Override
             public Drawable getDrawable(String source) {
                   Drawable drawable = null;
                   drawable = Drawable.createFromPath(source);  // Or fetch it from the URL
                   // Important
                   drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable
                                 .getIntrinsicHeight());
                   return drawable;
             }
      };

EDIT: found another tutorial that I thought looked neat: http://androidjava.wordpress.com/2010/09/17/images-in-textview/

+5
source

Should this text be edited or just displayed? Another option might be to display your content in a WebView and compose text / images using direct html.

+1
source

Source: https://habr.com/ru/post/1750864/


All Articles