我想通过设置一个负面的'添加到TextView.setLineSpacing()来减少TextView中的行间距。除了底线被截断之外,它运作良好。如何减少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,如果需要,我可以修改字体文件。
是否发生内置的字体呢?或者其他任何自定义字体?这可能是因为字体没有报告正确的下降值。最后一行的 – kcoppock 2012-08-12 17:37:26
也是'LineSpacing of -30f'正在应用。这就是为什么最后一行看不到的原因。所以你可以在你的情况下设置30的底部填充... @ kcoppock我认为在'descent values'中没有任何错误' – 2012-08-12 17:43:27
@kcoppock,我得到了与typeface = Typeface.SANS_SERIF相同的问题; – user1139880 2012-08-12 21:24:50