我想通過設置一個負面的'添加到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