我正在尝试通过在TextView中设置负的“add”值来减小行间距。这个方法很有效,但底部的一行会被截断。
主要布局。
主要活动:(注意 )
这导致视图底部被截断(请注意底行的“g”): 似乎问题与错误的布局测量有关。如果我将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并修改字体文件(如果需要)。