Android 删除html图像后的额外空间

Android 删除html图像后的额外空间,android,html,textview,whitespace,Android,Html,Textview,Whitespace,我正在android Textview中显示html内容。我在获取html图像时遇到了一个奇怪的问题。图像嵌入后,观察到一个额外的空间。我尝试了以下链接中的建议: 但这些建议都没有奏效 我观察到的一件奇怪的事情是:如果我删除标记,并添加没有任何标记的文本,那么额外空间就会消失 例如: <div class="img_dv"><div class="img_dv_content"><img id="story_image_main" style="display

我正在
android Textview
中显示
html内容。我在获取html图像时遇到了一个奇怪的问题。图像嵌入后,观察到一个额外的空间。我尝试了以下链接中的建议:

  • 但这些建议都没有奏效

    我观察到的一件奇怪的事情是:如果我删除
    标记
    ,并添加没有任何标记的文本,那么
    额外空间
    就会消失

    例如:

    <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>
    

    我做错什么了吗?。我不知道这是
    textview
    问题还是
    html
    问题还是我的
    layout
    问题。请帮我解决这个问题。

    TextView
    s只支持有限的HTML标记子集,并不是显示HTML的最佳视图。改用
    WebView
     <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>
    
    <?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>
    
      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);
    
            }
        }