-1

我正在使用fromHtml()设置文本视图,并且我的 TextView 未设置在中心。在下图中,您可以在paragraf文本下方显示更大的空间,我不知道如何解决此问题,其他普通文本很好,但从Html 中它会在中心留下一些空间。

像这样设置文本视图

txtOffer.text = Html.fromHtml(<h1>Hello i am using your app</h1>, Html.FROM_HTML_MODE_LEGACY)

这是xml代码

 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/colorAccent"
            android:gravity="center">

            <android.support.v7.widget.AppCompatTextView
                android:id="@+id/txt_offer"
                style="@style/txt_heavy_oblique"
                android:gravity="center"
                android:padding="@dimen/ten_dp" 
                android:textColor="@android:color/white"
                android:textSize="@dimen/text_size_12" />

    </LinearLayout>

  <style name="txt_heavy_oblique" parent="ThemeOverlay.AppCompat.Light">
        <item name="android:textColor">@color/colorPrimaryText</item>
        <item name="android:textSize">@dimen/text_size_14</item>
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textAppearance">@style/AvenirHeavyOblique</item>
    </style>

在此处输入图像描述

4

2 回答 2

0

许多研究我发现了这个库,它非常有用并解决了我的问题

https://github.com/PrivacyApps/html-textview

感谢@Avinash Ajay Pandey 的支持。:)

于 2018-05-25T05:00:58.383 回答
0

不要在 html 中使用标签,它会产生边距问题。如果您只需要不同的大小,您可以使用简单的或,并且您可以为一个字符多次使用它。示例:“经典文本还可以,但越大越好”。

于 2018-05-24T10:54:23.210 回答