2

I am using textview to load the HTML text. The HTML text has images. I am using ImageGetter to load images. But the image is getting cropped in the right. Below is the code:

textView.setText(Html.fromHtml(htmlText, new ImageGetter() {                 
@Override
public Drawable getDrawable(String source) {
    String path = "/sdcard/" + source;
    Drawable bmp = Drawable.createFromPath(path);
    bmp.setBounds(0, 0, bmp.getIntrinsicWidth(), bmp.getIntrinsicHeight());
    return bmp; }}, null));
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
madhuri H R
  • 699
  • 1
  • 10
  • 26
  • you want set drawable at center of point ? – Hemant Parmar May 07 '18 at 10:22
  • You can use WebView instead to load the HTML content as it is, which renders the image. Still if you want to show image in TextView, refer here https://stackoverflow.com/questions/2865452/is-it-possible-to-display-inline-images-from-html-in-an-android-textview – Gokul Nath KP May 07 '18 at 10:25
  • @HemantParmar not center. But image should not crop. – madhuri H R May 07 '18 at 10:27
  • 1
    I have to load in listview. As using webview in listview is not an efficient I am using textview. @GokulNathKP – madhuri H R May 07 '18 at 10:28
  • Try using this lib. https://github.com/PrivacyApps/html-textview – Sabyasachi May 07 '18 at 10:37
  • If you simply want a bitmap in one of the sides (top, left, bottom, right - centered on that side, fully inside the view, not in the center of the View), you can use a compound drawable (or more, if you want more images - say left and right or top and bottom - or even all four). – Phantômaxx May 07 '18 at 10:46
  • You can use SpannableStringBuilder for example SpannableStringBuilder builder = new SpannableStringBuilder(); builder.append("test string ") .append(" ", new ImageSpan(getActivity(), R.drawable.my_icon), 0) .append(" okey"); textView.setText(builder); – Hardik Mehta May 07 '18 at 10:58

0 Answers0