【问题标题】:How to set line-height textView on Android如何在 Android 上设置行高 textView
【发布时间】:2014-12-29 15:32:41
【问题描述】:

我给出了我在应用程序中使用 textView 的以下属性。 (中间绿字)

<TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:textSize="20sp"
                android:textStyle="bold"
                android:gravity="center_horizontal"
                android:text="10/9"
                android:id="@+id/estimate_fertility_date"
                />

但是,示例图片中存在空格。我想设置这些空间,因为当 App 初始化时,它看起来很糟糕。

我研究了大约 1 小时,找到了一些答案,但它们不是我想要的答案。 https://stackoverflow.com/a/6864017/2834196

【问题讨论】:

  • 不确定您到底想做什么,但如果您似乎无法根据需要设置间距,也许首先将 android:includeFontPadding="false" 添加到您的 textview 以便默认填充不会影响您想要的间距,然后将顶部/底部填充或边距设置为 textview...

标签: android


【解决方案1】:

在普通的TextView 中绝对没有文本填充并不容易。一种方法是可以为TextView 设置一个负边距,或者只使用textview.setIncludeFontPadding(false) 在一定程度上减少填充。

【讨论】:

  • 我发现的唯一解决方案实际上对我的 textview 做了任何事情。但仍有一些填充。
【解决方案2】:

向边距添加负值对您有帮助吗?

<TextView
android:layout_marginTop="-10dp" />

【讨论】:

  • 我试过了,效果很好,但我不确定这种方法是否完全正确。尽管我给你一点:)
  • 好吧,如果TextView 包含多行怎么办?这不是一个正确的解决方案。 lineSpacingExtra 我认为是正确的选择。
猜你喜欢
  • 1970-01-01
  • 2016-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-18
  • 1970-01-01
  • 2012-09-29
相关资源
最近更新 更多