【问题标题】:Android: Set font family to textview before inflate xml fileAndroid:在膨胀 xml 文件之前将字体系列设置为 textview
【发布时间】:2016-08-29 11:58:52
【问题描述】:

我想将font family 设置为Textview

但我想在加载之前执行此操作xml

我的代码:

for(int i=0;i++;i<100000){    
    final View addNew = G.inflater.inflate(R.layout.post, null);
    TextView txtTitle = (TextView) addNew.findViewById(R.id.txtTitle);
    txtTitle.setText("" + i);
    txtTitle.setTypeface(Typeface.createFromAsset(context.getAssets(),"tahoma.ttf"));
}

这段代码需要时间 15-16 秒

但如果我不使用setTypeface 需要时间 2-3 秒

【问题讨论】:

  • 你是什么创造了文本视图的火箭>>>为什么你需要100000 TextView

标签: android android-inflate


【解决方案1】:

您可以使用绑定。看link

【讨论】:

    【解决方案2】:

    如果您不介意使用第三方库,我建议您尝试Calligraphy。你可以在 GitHub 页面上找到你需要的一切,它真的很容易使用。

    你只需要在你的Application类和Activity类中设置好,把你的字体放在assets文件夹中,然后你就可以使用XML中的字体了,像这样:

    <TextView
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fontPath="fonts/Roboto-Bold.ttf"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多