android - Android textview,将包含字符的文本分成几行
问题描述
我使用 TextView 的特殊字体在 Android 应用程序中显示音标。ə
但是如果文本包含字符,则 TextView 会分成几行:
ə
在字体是一样的字母e
。
有没有办法解决这个问题?
我在两部手机上测试过,都遇到了同样的问题。
XML 中的 TextView:
<?xml version="1.0" encoding="utf-8" ?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="#F5FDFB"
android:id="@+id/scrollview_page3"
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:gravity="center"
android:id="@+id/textview_pronunciation"
android:layout_gravity="center"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:text="kri`dVetI"
android:textColor="#368DEB"
android:textSize="18sp"
android:textStyle="normal" />
</LinearLayout>
</ScrollView>
字体被添加到资源中,我使用getFont
和setTypeface
方法以编程方式更改字体。
字体:
解决方案
此函数修复了 Xamarin 中的问题:
static SpannableString FixPhoneticFont(string phonetic)
{
SpannableString ret = new SpannableString(phonetic);
for (int i = 0; i < phonetic.Length; i++)
ret.SetSpan(new RelativeSizeSpan(1f), i, i + 1, 0);
return ret;
}
推荐阅读
- spring-boot - 单元测试用例中的@KafkaListener 不会从容器工厂中消耗
- node.js - 快速启动 Angular 应用程序
- java - 在java中使用+声明一个长字符串
- node.js - 使用日期选择器限制天数
- sql - golang sql指针值不断重复
- ios - Redis ios客户端以安全方式使用websocket
- reactjs - 无法读取 null 的属性“ownerDocument”
- module - 如何将 lmod 与鱼一起使用?
- flowtype - 带有联合参数的函数间接导致联合成员出现莫名其妙的错误
- database - 我如何阅读 blcokfile_xxxx