同时滚动多个 TextView [英] Scroll multiple TextViews simultaneously
本文介绍了同时滚动多个 TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个来自文件的字符串,该字符串存储到 3 个单独的 TextView 中,因为我在使用单个 TextView 时遇到了对齐问题.如何仅滚动屏幕的这一部分以查看文件的所有内容?
I have a string from a file that am storing into 3 separate TextViews because I was having alignments issues with a single TextView. How can I scroll only this section of my screen to see all of the contents of the file?
BufferedReader buf = new BufferedReader(new FileReader(file));
while((line = buf.readLine())!= null) {
StringTokenizer st = new StringTokenizer(line);
a = st.nextToken();
b = st.nextToken();
c = st.nextToken();
text1.append(a + '\n');
text2.append(b + '\n');
text3.append(c + '\n');
}
dp1.setText(text1);
dp2.setText(text2);
dp3.setText(text3);
推荐答案
如果需要,您可以使用以下 xml 并进行一些调整,
You can use the following xml with a few tweaks if needed,
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:id="@+id/dp1"... />
<TextView android:id="@+id/dp2"... />
<TextView android:id="@+id/dp3"... />
</HorizontalScrollView>
现在在你的java代码中,你可以访问它们,
And now in your java code, you can access them as,
TextView textV1 = (TextView)findViewById(R.id.dp1);
TextView textV2 = (TextView)findViewById(R.id.dp2);
TextView textV3 = (TextView)findViewById(R.id.dp3);
textV1.setText(text1);
textV2.setText(text2);
textV3.setText(text3);
如果你愿意,你可以使用垂直滚动条,
if you want you can use vertical scroll bars as,
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:scrollbars="vertical"
android:layout_height="set the height here" >
</ScrollView>
这篇关于同时滚动多个 TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文