2011-11-13 114 views
1

我有一個字符串從一個文件存儲到3個單獨的TextViews,因爲我有一個單一的TextView的路線問題。我如何只滾動屏幕的這一部分來查看文件的所有內容?同時滾動多個TextView

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); 

回答

0

如果需要,可以使用下面的XML有一些調整,

<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代碼中,你可以訪問他們的,

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); 

,如果你願意,你可以使用垂直滾動條爲,

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:scrollbars="vertical" 
    android:layout_height="set the height here" > 

</ScrollView> 
+0

我試過了,它似乎沒有工作。它滾動屏幕上的固定區域,但不是位於TextViews –

+0

內的實際列表,您放置SrollView的方式出現了一些問題。我已經嘗試過它正常工作。檢查你的代碼一次...... :) – Kishan

+0

不可能將多個子代指定給'Horizo​​ntalScrollView'。 – TranslucentCloud

1

你可以把一個Horizo​​ntalScrollView裏面你TextViews在XML文件中,這樣

<HorizontalScrollView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <TextView ... /> 
    <TextView ... /> 
    <TextView ... /> 
</HorizontalScrollView> 
+0

無法爲'Horizo​​ntalScrollView'指定多個子項。 – TranslucentCloud

1

在佈局文件你textViewssetSelected(true)在你的代碼中你要設置的文字設定android:ellipsize="marquee"。我希望這能幫到您。