How to display html content with JPG and GIF images in it in TextView in RecyclerView?

299 Views Asked by At

I have RecyclerView with simple items. But I need to display html formatted text in TextView. But this html can contain tags, and I need to display that images in TextView (if there are GIF files - I need to show them animated).

Sample input html:

<div class="zd-comment" dir="auto">
<img data-original-height="240" data-original-width="320" src="https://media1.giphy.com/media/9uoYC7cjcU6w8/giphy.gif?cid=07c34cb67rkjrab20ed979a29kc7w9dju83awpeyr7f9ibue&amp;rid=giphy.gif&amp;ct=g" style="height: 225px; width: 300px"><br>via <a href="https://giphy.com/gifs/mrw-good-meagan-9uoYC7cjcU6w8" rel="noreferrer">GIPHY</a>
<br><img data-original-height="323" data-original-width="292" src="https://media3.giphy.com/media/v1.Y2lkPTA3YzM0Y2I2c2k2aTJ4aHdzb3J4ajV2ZHdocWhjM3dpNXY2ejlibzU1ZG9sYnk5NCZjdD1n/kaq6GnxDlJaBq/giphy.gif" style="height: 332px; width: 300px">
<br>via <a href="https://giphy.com/gifs/chloe-concerned-kaq6GnxDlJaBq" rel="noreferrer">GIPHY</a><br><img data-original-height="256" data-original-width="245" src="https://media3.giphy.com/media/xSM46ernAUN3y/giphy.gif?cid=07c34cb6si6i2xhwsorxj5vdwhqhc3wi5v6z9bo55dolby94&amp;rid=giphy.gif&amp;ct=g" style="height: 314px; width: 300px">
<br>via <a href="https://giphy.com/gifs/stoner-sees-isopropyl-xSM46ernAUN3y" rel="noreferrer">GIPHY</a>
<br><img data-original-height="200" data-original-width="333" src="https://media2.giphy.com/media/R3iDw0Me2Yw48/200.gif?cid=07c34cb6hd5my5n1e6jysr6rrozgmt6eq78x4h2xm0y9sh3s&amp;rid=200.gif&amp;ct=g" style="height: 180px; width: 300px"><br>via <a href="https://giphy.com/gifs/R3iDw0Me2Yw48" rel="noreferrer">GIPHY</a>
<br><img data-original-height="200" data-original-width="273" src="https://media1.giphy.com/media/QgixZj4y3TwnS/200.gif?cid=07c34cb6hd5my5n1e6jysr6rrozgmt6eq78x4h2xm0y9sh3s&amp;rid=200.gif&amp;ct=g" style="height: 221px; width: 300px"><br>via <a href="https://giphy.com/gifs/reaction-of-almost-QgixZj4y3TwnS" rel="noreferrer">GIPHY</a><br>
</div>

I have tried such solutions:

  1. Display that html in WebView; (but I had issues that web view was not reused in other rows of RV);
  2. I was using TextView in which I was setting Spannable;
  3. Using this library: https://github.com/SufficientlySecure/html-textview -- but it's not displaying animated Gifs.

If someone knows how to properly display html content and it's images (gifs also) in TextView or correctly recycler WebView - please help with that. Thanks.

0

There are 0 best solutions below