我在Android TextView.
Typeface tf = Typeface.createFromAsset(getAssets(),
"nunitomedium.ttf");
txt2= (TextView) findViewById(R.id.txt2);
txt2.setTypeface(tf);
但是线条之间的填充没有正确显示。
<TextView
android:id="@+id/txt2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_10sdp"
android:layout_marginRight="@dimen/_10sdp"
android:layout_marginTop="@dimen/_15sdp"
android:text="You can send emergency blast to friends and family whenever you feel uncomfortable. Once activated, you will be able to send an emergency blast to your safety network within seconds with the pressing of one button."
android:textColor="@color/colorBlack"
android:textSize="@dimen/_15sdp" />
这是我的输出:
我也试过以下代码:
android:includeFontPadding="false"
但仍然是同一个问题。不确定,但我也尝试使用Here中的justifyTextView
但同样的问题。以前有人遇到过同样的问题吗?
提前致谢。
编辑:
如果我使用android:lineSpacingExtra
第一行有更多空间,那么其他行。这是我的代码和输出。
<TextView
android:id="@+id/txt2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_10sdp"
android:layout_marginRight="@dimen/_10sdp"
android:layout_marginTop="@dimen/_15sdp"
android:lineSpacingExtra="@dimen/_5sdp" <<<<<<<
android:text="You can send emergency blast to friends and family whenever you feel uncomfortable. Once activated, you will be able to send an emergency blast to your safety network within seconds with the pressing of one button."
android:textColor="@color/colorBlack"
android:textSize="@dimen/_15sdp" />
答案 0 :(得分:2)
关于这一点的晚会 - 我们有完全相同的问题,通过用最新的谷歌字体替换.ttf字体文件完全修复 - 这个字体的早期版本很糟糕。不要忘记删除你同时放置的任何android:lineSpacingMultiplier
软糖。
答案 1 :(得分:0)
在XML中添加linespacingMultiplier
<TextView
android:id="@+id/textview_font"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_10sdp"
android:layout_marginRight="@dimen/_10sdp"
android:layout_marginTop="@dimen/_15sdp"
android:text="You can send emergency blast to friends and family whenever you feel uncomfortable. Once activated, you will be able to send an emergency blast to your safety network within seconds with the pressing of one button."
android:textColor="@android:color/black"
android:lineSpacingMultiplier="3"
android:textSize="@dimen/_15sdp" />
或
在代码中添加以下行: -
mTextViewFont=(TextView)findViewById(R.id.textview_font);
Typeface tf = Typeface.createFromAsset(getAssets(),
"nunitomedium.ttf");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mTextViewFont.setLineSpacing((float) 5.5,(float) 1.2);
}
mTextViewFont.setTypeface(tf);
答案 2 :(得分:0)