【发布时间】:2012-08-12 17:33:45
【问题描述】:
我正在尝试通过为 TextView.setLineSpacing() 设置负“添加”来减少 TextView 中的行间距。它运作良好,只是底线被截断。
主布局
<TextView
android:id="@+id/text_view"
android:padding="dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
tools:context=".MainActivity" />
主要活动:(注意
package com.font_test;
import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/custom_fonts.ttf");
final TextView tv = (TextView) findViewById(R.id.text_view);
tv.setTypeface(typeface);
tv.setTextSize(60);
tv.setLineSpacing(-30f, 1f); // *** -30 to reduce line spacing
tv.setBackgroundColor(0x280000ff);
tv.setText("gggkiiikkk" + "\n" + "gikgikgik" + "\n" + "kigkigkig");
}
}
这会导致视图底部被截断(注意底部的“g”):
问题似乎与不正确的布局测量有关。如果我将 TextView 设置为
android:layout_height="fill_parent"
它确实呈现正确:
知道如何解决吗?如果有帮助,我不介意有丑陋的解决方法。我还可以访问 FontForge,如果需要,我可以修改字体文件。
【问题讨论】:
-
内置字体也会发生这种情况吗?或者任何其他自定义字体?可能是字体没有报告正确的下降值。
-
最后一行
LineSpacing of -30f正在申请。这就是为什么最后一行没有正确看到的原因。所以你可以set bottom paddingof 30 在你的情况下...@kcoppock 我认为descent values没有任何问题 -
@kcoppock,我遇到了同样的问题 typeface = Typeface.SANS_SERIF;
-
@Mohsin,添加 android:paddingBottom="60dp" 在底部添加了边距,但字体仍被截断。见imgur.com/du5xJ
标签: android fonts textview truetype