简体   繁体   English

当我使用Assets中的字体时,Android listview不流畅

[英]Android listview is not fluid when i use font from Assets

I use this code to set Roboto font to a Textview for each item if my list. 如果我的列表,我使用此代码将Roboto字体设置为每个项目的Textview。

It works fine but when i scrolml the list, it's not fluid whereas with default font, the list is verry fluid when i scroll. 它运行正常但是当我滚动列表时,它不是流畅的,而使用默认字体,当我滚动时列表是非常流畅的。

TextView premiereLettre = (TextView) rowView.findViewById(R.id.premiere_lettre);
Typeface face = Typeface.createFromAsset(getContext().getAssets(), "fonts/Roboto-Light.ttf");
premiereLettre.setTypeface(face);

What is the problem ? 问题是什么 ?

Can i make an enhancement for this code ? 我可以对此代码进行增强吗?

Thanks a lot 非常感谢

Problem is that you create TextView object, and most importantly a Typeface object each time you create a row. 问题是您每次创建一行时都创建TextView对象,最重要的是创建一个Typeface对象。 Create them once in your class (you can use ViewHolder for your TextView , and a class level variable for Typeface that you instantiate in your constructor) 在类中创建它们一次(您可以将ViewHolder用于TextView ,并在构造函数中实例化Typeface的类级变量)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该在什么时候使用资产而不是 Android 中的原始资源? - When should I use the assets as opposed to raw resources in Android? 在Android中,我可以在布局xml中使用资源中的图像吗? - In Android, can I use image from assets in layout xml? 使用资产使用Android的Listview? - Listview using assets Android? 在展开式列表视图中单击子项时,如何从资产中获取特定的文本文件 - How do i get a specific text file from assets when a click a child in expandable listview 如何在Android中将资产文件夹中的自定义字体设置为操作栏的标题? - How to set a custom font from the assets folder to the title of an Actionbar in Android? 从 Android 中的 XML 文件访问 assets 文件夹下的字体 - Accessing a font under assets folder from XML file in Android 当我使用自定义适配器时,如何从Android中的ListView获取数据 - How to get data from ListView in Android when I use custom adapter 从 Android Gradle 构建中排除库的资产(在本例中为字体)是否安全? - Is it safe to exclude libraries' assets (font in this case) from an Android Gradle build? Android:使用资产文件时ZipFile,FileNotFoundException - Android: ZipFile, FileNotFoundException when use Assets Files 在Android中使用AlertDialog时无法禁用ListView项目 - I cannot disable a ListView item when I use an AlertDialog in Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM