Android自定义字体(nunito)未在TextView中正确设置

Android自定义字体(nunito)未在TextView中正确设置,android,textview,custom-font,android-typeface,Android,Textview,Custom Font,Android Typeface,我在androidTextView中使用自定义字体。 Typeface tf = Typeface.createFromAsset(getAssets(), "nunitomedium.ttf"); txt2= (TextView) findViewById(R.id.txt2); txt2.setTypeface(tf); 但是行间的填充并没有正确显示 <TextView android

我在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" />
但还是一样的问题。不确定,但我也尝试使用相同问题的
justifyTextView
。以前有人遇到过同样的问题吗

提前谢谢

编辑:

如果我使用android:lineSpacingExtra1行比其他行有更多的空间。这是我的代码和输出

<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" />

在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" />

字体文件中出现了问题,这是因为您下载该文件的站点。我从

dafontfree.net/download-nunito-f92263.htm

然后替换资产文件夹中的文件

这就是它的输出



派对迟到了-我们遇到了完全相同的问题,通过使用Google字体的最新版本替换.ttf字体文件得到了完全修复-这种字体的早期版本很糟糕。别忘了删除您在这段时间内放置的任何
android:lineSpacingMultiplier
fudges。

也共享您的ttf文件@Hardik JoshiHardik Joshi我正在使用三星设备,在该文本视图中正确显示。对我来说,它看起来像是一些问题font@Ankita这是我的字体文件@林格什瓦兰:嗯,似乎是特定于设备的问题?但第一行间距比所有其他行都大得多。主题本身就是字体中的一个bug与@VladMatvienko一致,但第1行的间距比所有其他行都大。字体文件中出现了问题,这是因为您下载它的站点。我从下载文件,然后从资产文件夹替换您的文件@HardikJoshiI已将答案与输出分享(截图)@HardikJoshiOk让我检查一下并让你知道。你好@Ankita,不幸的是,这在我这边不起作用。你在使用模拟器吗?或者在真实设备中显示相同的输出?我正在使用emulator。我在同一个模拟器上运行您的代码,但它没有正确显示。但当我回复ttf文件时,它工作正常@请检查我的代码。是一样的吗?你从我给你的链接下载了ttf文件吗?嘿@Fisk谢谢你的回复。如果可能的话,你也可以共享字体文件吗?谢谢非常感谢您对@Fisk的帮助。你做到了。我过去一直在研究这个问题。我用默认字体保存它。但现在我也在我的应用程序中使用nunito字体。谢谢你,兄弟。快乐编码。:)
 <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);