2012-05-11 31 views
0

我要滾動,在一個TextView查看結果的滾動水平和垂直方向的內容,這是我的xml:如何讓一個TextView

<scroll> 
<TextView 
android:id="@+id/ris" 
android:layout_width="wrap_content" 
android:layout_height="229dp" 
android:layout_weight="0.96" 
android:textAppearance="?android:attr/textAppearanceMedium" /> 
</scroll> 

,但應用程序崩潰。

+0

你試圖做什麼來解決崩潰?崩潰的消息說什麼? – jamesTheProgrammer

回答

1

使用

<ScrollView> your View "</ScrollView"> 

而且必須有隻有一個孩子滾動型。

1

在XML文件中添加本作的TextView

android:scrollHorizontally="true" 
android:scrollVertically="true" 
1

添加如下屬性在TextView

android:maxLines = "1" 
android:scrollbars = "vertical" 

然後,一旦你實例化你的TextView,添加一行:

mTextView.setMovementMethod(new ScrollingMovementMethod()); 
+0

+1不知道這個! –

0
<ScrollView 
    android:id="@+id/scrollView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="19dp" 
    android:layout_marginTop="24dp" > 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/tv" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/hello_world" 
      tools:context=".Tester" /> 
    </LinearLayout> 
</ScrollView> 
+1

通過將TextView放在ScrollView中,您將獲得ScrollView的行爲,例如垂直滾動。 –

+0

請做解釋 – johannes