我可以轻松地在 Android/java/ 中的交替行上显示文本吗?

Can I easily display text on alternating lines in Android/java/

我有一个雄心勃勃的格式化问题,它有几个部分,而且我对 Android 编程只有一个初学者的掌握。我想交替显示来自两个不同文件的文本:

This is text from the first file, which is different from the second file. The 
This is the text from the second file. Notice that it isn’t a lot like the first

differences are pretty great, but take (overall) nearly the same number of 
file, but has a similar number of characters. The contents of the second 

characters, plus or minus about 5%
file should be nearly the same in length.

想法是在 phone 上以合理(且可调整)的字体大小显示此内容,行的长度受文本框大小的限制。我想我需要为每个文本框弄清楚有多少字符适合,找到一种方法来写那么多(或更少,在 space 或 . 或 ! 或?)处拆分并继续下一个文本框。由于文件很长,我需要一种方法来滚动(似乎不太可能)或整页刷新显示。

我的问题:

  1. 我的攻击计划合理吗?
  2. 有没有可以简化这个过程的库?
  3. 如果这种攻击真的很愚蠢,谁能提出更好的方法?

即使您的想法是可行的方法,让我建议另一种选择:利用您可以将两个 TextView 放置在 Android[= 中几乎相同的位置这一事实18=]

每个TextView可以显示其中一个文件的行。两者的行高都是字体大小要求的三倍(使用 android:lineSpacingMultiplier)。如果你把第二个 TextView 放在比第一个稍微低一点的地方(使用 android:marginTop),那么你会得到如下的模式:

布局xml示例:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    tools:context=".PlusOneFragment">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="16sp"
        android:lineSpacingMultiplier="3"
        android:text="@string/textview1_text" />

    <TextView
        android:layout_marginTop="18dp"
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="16sp"
        android:lineSpacingMultiplier="3"
        android:text="@string/textview2_text" />

</FrameLayout>

strings.xml 包含

<string name="textview1_text">This is text from the first file, which is different from the second file. The differences are pretty great, but take (overall) nearly the same number of characters, plus or minus about 5%</string>
<string name="textview2_text">This is the text from the second file. Notice that it isn’t a lot like the first file, but has a similar number of characters. The contents of the second  file should be nearly the same in length.</string>