3

I'm displaying the html content in android Textview. I'm facing a strange issue while fetching the html images. After the image embed, an extra space is observed. I Tried what suggested in the below links:

  1. http://salman-w.blogspot.in/2012/10/remove-space-below-images-and-inline-block-elements.html

  2. Mysterious gap under image appearing

  3. Remove white space below image

But none of the suggestions worked.

And one strange thing, that I observed is: If i remove the tag, and add the text without any tag, then extra space disappears.

For example:

<div class="img_dv"><div class="img_dv_content"><img id="story_image_main" style="display:block;" src="http://htmlimage.jpg" /><p class="img_dv_Caption">Photo Credit: Sample Image Caption</p></div></div>

This gives an extra space after the image.

But in the below code, there is no space:

 <div class="img_dv"><div class="img_dv_content"><img id="story_image_main" style="display:block;" src="http://htmlimage.jpg" />Photo Credit: Sample Image Caption</div></div>

But I have a separate style for caption. So, I must use a custom view, using which gives an extra space.

I also refered the below link and tried.

  1. How to remove the top and bottom space on textview of Android

And tried the solutions given in this link. But none of them is working.

Below is my custom view layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:padding="0dp"
    android:gravity="top">

    <com.ndtv.core.common.util.views.HtmlTextview
        android:id="@+id/img_caption"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="@color/img_caption_color"
        android:textSize="@dimen/img_caption_size"
        app:customTypeface="@string/roboto_light"
        android:padding="0dp"
        android:gravity="center|top"
        android:includeFontPadding="false"/>

    <View
        android:id="@+id/line_below_caption"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginTop="5dp"
        android:background="@color/img_caption_color"
        android:visibility="gone" />


</LinearLayout>

And this is how I'm setting the text to the textview:

  public static void createImageCaptionView(Context context, LinearLayout container, String source, Fragment fragment){
        if (context != null && container != null && fragment != null) {
            LayoutInflater inflater=LayoutInflater.from(context);
            View imageCaptionView=inflater.inflate(R.layout.img_caption_view, container, false);
            HtmlTextview imgCaption= (HtmlTextview) imageCaptionView.findViewById(R.id.img_caption);
            View lineBelowCaptiin=imageCaptionView.findViewById(R.id.line_below_caption);
            imgCaption.setHtmlFromString(Utility.decodeString(source),context);
            lineBelowCaptiin.setVisibility(View.VISIBLE);
            container.addView(imageCaptionView);

        }
    }

I'm I doing anything wrong here?. I'm not getting whether it's an textview issue or html issue or my layout issue. Please help me to solve this issue.

Community
  • 1
  • 1
Sangeetha Pinto
  • 1,022
  • 3
  • 14
  • 32
  • `TextView`s only support a **limited subset** of HTML tags, and aren't really the best View to use for displaying HTML. Use a `WebView`, instead. – Phantômaxx Nov 26 '15 at 08:51

0 Answers0