当我有一个TextView与一个\n在文本中,,在右边我有两个单线TextViews,一个在另一个之间没有间距。我已经为所有三个textview设置了以下内容。

android:lineSpacingMultiplier="1" 
android:lineSpacingExtra="0pt" 
android:paddingTop="0pt" 
android:paddingBottom="0pt"

第一行的左侧TextView线完美地与右上角TextView。

左TextView的第二行略高于右下TextView的第二行。

似乎有某种隐藏的填充顶部和底部的TextViews。我怎么才能去掉它呢?


当前回答

唯一有效的是

android:lineSpacingExtra="-8dp"

其他回答

我认为这个问题可以这样解决:

 <TextView
        android:id="@+id/leftText"
        android:includeFontPadding="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="30dp"
        android:text="Hello World!\nhello world" />

 <TextView
        android:id="@+id/rightUpperText"
        android:includeFontPadding="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/leftText"
        android:layout_alignTop="@+id/leftText"
        android:textSize="30dp"
        android:text="Hello World!" />

 <TextView
        android:id="@+id/rightLowerText"
        android:includeFontPadding="false"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/leftText"
        android:layout_below="@+id/rightUpperText"
        android:textSize="30dp"
        android:text="hello world" />

结果如下:

ScreenShot-1

ScreenShot-3

虽然rightLowerText中的特殊字符行看起来比leftText中的第二行高一些,但它们的基线仍然是对齐的。

你可以尝试使用这个属性(ConstraintLayout):layout_constraintBaseline_toBaselineOf

是这样的:

app: layout_constraintBaseline_toBaselineOf = @ + id / textView”

简单的方法奏效:

setSingleLine();
setIncludeFontPadding(false);

如果它没有工作,然后尝试添加这个代码:

setLineSpacing(0f,0f);
// and set padding and margin to 0

如果你需要多行,也许你需要通过临时单行TextView精确计算填充顶部和底部的高度(在删除填充之前和之后),然后应用降低高度结果与负填充或一些鬼布局翻译Y. Lol

我能感受到你的痛苦。我已经尝试了上面的每个答案,包括setIncludeFontPadding为false,这对我没有任何帮助。

我的解决方案吗?layout_marginBottom="-3dp"在TextView给你一个解决方案的底部, 砰!

虽然,-3dp在layout_marginTop失败....ugh。

你可以用这里列出的一些技巧来部分解决这个问题(负边距,字体填充等),但你不能绕过字体本身的大小[1]。在所有语言中,字体的每个“单元格”的固定高度必须足以容纳最高的字符。

如果你采用了其他答案中列出的技巧,字体可以被剪掉。

解决方案是向你的设计师解释字体是如何包装的,并让他们在设计中考虑到这一点。不要因为在翻译到其他语言时出现bug而现在就进行修改。

我想人们可以用压缩升序和降序来打包他们自己的字体。