Android studio 为什么启动应用程序时自定义字体只在几毫秒后出现?渲染问题?-安卓工作室
我有一个应用程序,它有一个启动屏幕,后面是一些文本视图的主要活动。Android studio 为什么启动应用程序时自定义字体只在几毫秒后出现?渲染问题?-安卓工作室,android-studio,textview,font-family,google-fonts,Android Studio,Textview,Font Family,Google Fonts,我有一个应用程序,它有一个启动屏幕,后面是一些文本视图的主要活动。 我正在使用字体系列“aladin”,我从属性>字体系列>更多字体中选择了它 问题是,当我启动我的应用程序时,启动屏幕会正确显示,但当我的主要活动之后,在毫秒内,你可以看到我的文本视图中的字体正在从“默认”跳到aladin。 换句话说,aladin字体的渲染/加载似乎花费了太多时间 我如何解决这个问题?? 我已经尝试过将textsize从sp改为dp,但这并不能解决我的问题 阿拉丁字体应该立即出现,而不是在毫秒后,它看起来不太好
我正在使用字体系列“aladin”,我从属性>字体系列>更多字体中选择了它 问题是,当我启动我的应用程序时,启动屏幕会正确显示,但当我的主要活动之后,在毫秒内,你可以看到我的文本视图中的字体正在从“默认”跳到aladin。
换句话说,aladin字体的渲染/加载似乎花费了太多时间 我如何解决这个问题??
我已经尝试过将textsize从sp改为dp,但这并不能解决我的问题 阿拉丁字体应该立即出现,而不是在毫秒后,它看起来不太好 事先非常感谢
<TextView
android:id="@+id/textViewItem"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_marginBottom="0dp"
android:fontFamily="@font/aladin"
android:gravity="center|center_horizontal"
android:textColor="#000000"
android:textSize="26sp" />
我也有类似的问题;当应用程序启动时,文本会以默认字体显示几秒钟,然后以自定义字体重新绘制。这可能不会困扰大多数用户,但肯定是显而易见的 我还发现,一旦加载了自定义字体,随后的文本就不会首先显示默认字体 因此,我的工作方法是在启动屏幕显示时加载自定义字体。首先,准备自定义字体
[res/font/ubuntu_mono.xml]
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto"
app:fontProviderAuthority="com.google.android.gms.fonts"
app:fontProviderCerts="@array/com_google_android_gms_fonts_certs"
app:fontProviderPackage="com.google.android.gms"
app:fontProviderQuery="Ubuntu Mono">
</font-family>
[res/font/ubuntu\u mono.xml]
[res/value/preload_fonts.xml]
@字体/ubuntu\u mono
[AndroidManifest.xml]
...
然后在启动屏幕的布局中,添加一个没有文本的文本视图。这将加载自定义字体,当主显示时,自定义字体将准备就绪
[res/layout/splash.xml]
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text=""
app:fontFamily="@font/ubuntu_mono" <-- custom font
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
[res/layout/splash.xml]
...
我也有类似的问题;当应用程序启动时,文本会以默认字体显示几秒钟,然后以自定义字体重新绘制。这可能不会困扰大多数用户,但肯定是显而易见的
我还发现,一旦加载了自定义字体,随后的文本就不会首先显示默认字体
因此,我的工作方法是在启动屏幕显示时加载自定义字体。首先,准备自定义字体
[res/font/ubuntu_mono.xml]
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:app="http://schemas.android.com/apk/res-auto"
app:fontProviderAuthority="com.google.android.gms.fonts"
app:fontProviderCerts="@array/com_google_android_gms_fonts_certs"
app:fontProviderPackage="com.google.android.gms"
app:fontProviderQuery="Ubuntu Mono">
</font-family>
[res/font/ubuntu\u mono.xml]
[res/value/preload_fonts.xml]
@字体/ubuntu\u mono
[AndroidManifest.xml]
...
然后在启动屏幕的布局中,添加一个没有文本的文本视图。这将加载自定义字体,当主显示时,自定义字体将准备就绪
[res/layout/splash.xml]
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text=""
app:fontFamily="@font/ubuntu_mono" <-- custom font
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
[res/layout/splash.xml]
...
能否将启动屏幕的显示延迟到。字体已加载?@BanksySan我不确定是否正确理解了您的问题:我使用了延迟时间1500,正如您现在在编辑的问题中看到的那样。这有用吗?即使在这个延迟之后,当Splashscreen消失时,字体仍会改变一毫秒。这里也有同样的问题@BanksySan,我怎么知道字体是否已加载?是否有回调?能否延迟显示初始屏幕,直到加载字体为止?@BanksySan我不确定是否正确理解了您的问题:我使用了延迟时间1500,正如您现在在编辑的问题中看到的那样。这有用吗?即使在这个延迟之后,当Splashscreen消失时,字体仍会改变一毫秒。这里也有同样的问题@BanksySan,我怎么知道字体是否已加载?有回电吗?
[AndroidManifest.xml]
...
<meta-data
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts" />
[res/layout/splash.xml]
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraint_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text=""
app:fontFamily="@font/ubuntu_mono" <-- custom font
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>