微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – TextView和EditText中的TextRendering

我有一个像这样的简单布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <EditText
        android:id="@+id/txtContent2"
        android:layout_width="300dp"
        android:layout_height="100dp"
        android:background="#fed9f4"
        android:textSize="22sp" />
    <View
        android:layout_width="match_parent"
        android:layout_height="10dp"/>

    <TextView
        android:id="@+id/txtBelow"
        android:layout_width="300dp"
        android:layout_height="100dp"
        android:background="#fed9f4"
        android:textSize="22sp"/>
</LinearLayout>

TextView和EditText.
当我在它们中设置相同的文本时,似乎每个文本都以不同的方式呈现文本.如下:

Top view is EditText and below is TextView

我正在使用StaticLayout来测量文本并识别每行中的文本边界,我必须将文本设置为TextView(因此用户无法编辑或选择它).

但似乎StaticLayout文本边界计算与EditText匹配而不是TextView.

StaticLayout layout = new StaticLayout(content,txtContent.getPaint(),txtContent.getWidth(),Layout.Alignment.ALIGN_norMAL,1,linespace,false);

我的问题是为什么TextView和EditText中的文本呈现不同以及我如何使用StaticLayout测量文本并将文本设置为TextView,以便每行的开始和结束偏移与用户在setText之后看到的结果完全匹配

解决方法

尝试为两个视图设置相同的 breakStrategyhttps://developer.android.com/reference/android/widget/TextView.html#attr_android:hyphenationFrequency enter link description here,因为它们可能与EditText和TextView认值不同.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐