使用HTML格式时从TextView删除底部填充 [英] Removing the bottom Padding from a TextView while using HTML Format
本文介绍了使用HTML格式时从TextView删除底部填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试像这样在 TextView
上设置html文本
I try set my html text on TextView
like this
my_text.setText(HtmlCompat.fromHtml("<p>This is the awesome place to gain</p><p><strong>awesomeness </strong>and <em>deliciuosness. </em>very<em> </em><u>nice</u></p>", HtmlCompat.FROM_HTML_SEPARATOR_LINE_BREAK_PARAGRAPH))
我尝试为 TextView
设置边框,然后像这样填充底部.
I try set the TextView
with a border, And I got padding bottom like this.
如何删除?因为我的 TextView
没有设置任何内容
How to remove that? Because My TextView
doesn't set anything
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/my_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/border_black_fill_white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
推荐答案
在 kotlin 中,它只是使用 trim()
方法:
In kotlin it's just using trim()
method:
val stringHtml = "<p>This is the awesome place to gain</p><p><strong>awesomeness </strong>and <em>deliciuosness. </em>very<em> </em><u>nice</u></p>"
val spannedHtml = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
Html.fromHtml(stringHtml, Html.FROM_HTML_MODE_COMPACT)
} else {
Html.fromHtml(stringHtml)
}
my_text.text = spannedHtml.trim()
这篇关于使用HTML格式时从TextView删除底部填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文