增加文本大小会为android中的文本添加额外的填充

时间:2018-01-19 10:53:48

标签: android textview

我面临一个简单的问题。我在xml中增加textSize。当我增加textSize时,文本周围会出现一些额外的填充。我不想要那个。

enter image description here

这是我的代码:

<TextView
android:id="@+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="70sp"
android:gravity="bottom"
android:includeFontPadding="false"
android:lineSpacingExtra="0dp"
android:text="1"/>

如何删除框内的空格?

1 个答案:

答案 0 :(得分:0)

试试这个在xml中运行得很好

  <TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Rizwan"
    android:padding="@null"
    android:includeFontPadding="false"
    />

如果你想在java中使用它就像这样

youtextView.setIncludeFontPadding (false)

注意!:你可以使用负填充或点数,但不推荐使用,因为这是android的内置boxModel填充

如果它不能正常工作,如OFFICIAL DOC中所述,每个字体周围都有自己的白色间距

尝试在资产文件夹中使用自定义字体而不是默认的ROBOTO,就像在这个令人敬畏的项目here

中完成的那样

归功于@Sunilkushwah。他使用&#34; HVD字体--BrandonText-Light.otf&#34;它确实解决了这个问题

相关问题