繁体   English   中英

TextView:删除顶部和底部的间距和填充

[英]TextView: Remove spacing and padding on top and bottom

我有一个大小为 50 dp 的文本视图。 我得到了如下图所示的结果。 在此处输入图片说明
我想删除 textView 中的底部空格,因为它的高度取决于文本大小。 而且我只想在我的引号中接收背景。 有没有办法删除我的 textView 中未使用的空格?

<TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="top"
                android:text="“"
                android:fontFamily="@font/arialbd"
                android:background="#ff0"
                android:textColor="#E8E9EF"
                android:includeFontPadding="false"
                android:textSize="50dp" />

尝试这个:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_gravity="top|center"
    android:text="“"
    android:fontFamily="@font/arialbd"
    android:background="#ff0"
    android:textColor="#E8E9EF"
    android:includeFontPadding="false"
    android:textSize="50dp"
    android:gravity="top" />

此解决方案适用于我的情况。 去除底部填充。 layout_height设置为与textSize相同的大小或小于 1dp 或 2dp。
设置includeFontPadding="false" 设置android:lineSpacingExtra="0dp"

在您的情况下,您必须实现自定义 textView。 检查此示例以供参考。

您可以尝试将底部边距设置为负值。

像这样的东西:

android:layout_marginBottom="-10dp"

让我知道它是否有效,这是最简单的方法,但可以是其他方法......

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM