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认值不同.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...