我有一个雄心勃勃的格式化问题,它有好几个部分,而我对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.
我的想法是在手机上以合理的(可调整的)字体大小显示,行的长度由文本框的大小限制。我想我需要计算出每个文本框能容纳多少字符,找到一种方法来写出这么多字符(或更少的字符,用空格或.或!或?),然后继续下一个文本框。由于文件相当长,我需要一种方法来滚动(似乎不太可能)或整页刷新显示。
我的问题是:我的攻击计划是否合理?
即使你的想法是一个可行的方法,让我提出另一个方案:利用你可以将两个 TextView
的在安卓系统中几乎相同的位置
每个 TextView
可以显示其中一个文件的行。两者的行高都将是字体大小要求的三倍(使用 android:lineSpacingMultiplier
). 如果你把第二个 TextView
比第一种低一点(用 android:marginTop
),然后你会得到一个类似下面的模式。
layout xml example:
<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>