【问题标题】:TextView: Remove spacing and padding on top and bottomTextView:删除顶部和底部的间距和填充
【发布时间】:2019-02-12 15:47:37
【问题描述】:

我有一个大小为 50 dp 的 textview。我得到了如下图所示的结果。
我想删除 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" />

【问题讨论】:

    标签: android android-activity android-linearlayout textview


    【解决方案1】:

    试试这个:

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        在您的情况下,您必须实现自定义 textView。参考this example。

        【讨论】:

          【解决方案4】:

          你可以尝试将下边距设置为负值。

          类似这样的:

          android:layout_marginBottom="-10dp"
          

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

          【讨论】:

          • 我认为负边距是一种不好的做法。
          猜你喜欢
          • 2011-06-13
          • 2020-12-05
          • 2019-12-29
          • 1970-01-01
          • 2018-04-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多