我有一个应用程序,可以更改某些元素的字体字体.它适用于大多数人,但在尝试更改字体时可能会有0.5%的异常.堆栈跟踪的重要部分是:
Caused by: java.lang.RuntimeException: native typeface cannot be made
at android.graphics.Typeface.<init>(Typeface.java:147)
at android.graphics.Typeface.createFromAsset(Typeface.java:121)
Run Code Online (Sandbox Code Playgroud)
正如我所说,它适用于大多数人,所以我不认为这是字体文件或我的代码的问题.有关如何解决这个问题的任何建议?
编辑:这是我的代码:
Typeface phoneticFont = Typeface.createFromAsset(getAssets(),
"fonts/CharisSILR.ttf");
TextView tv;
tv = ((TextView) findViewById(R.id.searchPronunciationTitle));
tv.setTypeface(phoneticFont);
Run Code Online (Sandbox Code Playgroud) 我想将 Pydantic 模型导出到 YAML,但避免重复值并使用引用(锚+别名)。
这是一个例子:
from typing import List
from ruamel.yaml import YAML # type: ignore
import yaml
from pydantic import BaseModel
class Author(BaseModel):
id: str
name: str
age: int
class Book(BaseModel):
id: str
title: str
author: Author
class Library(BaseModel):
authors: List[Author]
books: List[Book]
john_smith = Author(id="auth1", name="John Smith", age=42)
books = [
Book(id="book1", title="Some title", author=john_smith),
Book(id="book2", title="Another one", author=john_smith),
]
library = Library(authors=[john_smith], books=books)
print(yaml.dump(library.dict()))
Run Code Online (Sandbox Code Playgroud)
我得到:
authors:
- age: 42
id: auth1
name: John Smith
books:
- author: …Run Code Online (Sandbox Code Playgroud) 我有一个TextView,它显示一个带有一些HTML的字符串,用于更改格式.我使用此代码执行此操作:
text = "What symbol do 'all, only, <b>l</b>ike' have in common?";
title.setText(Html.fromHtml(text));
Run Code Online (Sandbox Code Playgroud)
问题是在不需要时会插入一个新行字符,即我得到这个:
What symbol do 'all, only,
like'
have in common?
Run Code Online (Sandbox Code Playgroud)
"仅"之后的休息是正确的(那条线上没有空间),但不需要"喜欢"之后的休息.
我一直在做测试,如果在字符串中我将粗体标记从"like"中的"l"更改为"only"中的"l",即,我有:
text = "What symbol do 'all, on<b>l</b>y, like' have in common?";
Run Code Online (Sandbox Code Playgroud)
文本被正确破坏:
What symbol do 'all, only,
like' have in common?
Run Code Online (Sandbox Code Playgroud)
这让我感到困惑,因为它除了那个字符串之外完全相同,并且不应该对行长度产生影响.
难道我做错了什么?这是一个错误吗?
更新: XML中的TextView如下所示:
<TextView
android:textAppearance="?android:textAppearanceLarge"
android:textColor="#ff000000"
android:id="@+id/title"
android:paddingLeft="10.0sp"
android:paddingRight="10.0sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Waiting for initialization..." />
Run Code Online (Sandbox Code Playgroud) 我有一个Google Maps API v2的自定义信息窗口,它使用通过在我的班级覆盖getInfoWindow添加的RelativeLayout.这个布局有一个TextView,第一行有一个标题,下一行有三个TextView,一个对齐到左边,另一个对齐到中心,第三个对齐到右边.它可以工作,但窗口占据了整个屏幕,这在平板电脑等大屏幕上非常难看.
我试图将RelativeLayout的宽度设置为某个固定值(比如说"50dp")或"wrap_content",但它总是需要整个屏幕.
这是布局的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bus_stop_info_window"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffffffff" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="A title" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:gravity="left"
android:text="Test1" >
</TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:gravity="center"
android:text="Test2" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:gravity="left"
android:text="Test3" >
</TextView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我怎样才能达到预期的效果?