首页 > 解决方案 > 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>

字体被添加到资源中,我使用getFontsetTypeface方法以编程方式更改字体。

字体:

在此处输入图像描述

标签: androidtextview

解决方案


此函数修复了 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;
    }

推荐阅读