2016-05-31 194 views
2

我的Android TextView xml非常簡單,就像下面一樣,我使用ScrollView風格,但它不會顯示滾動條,即使文本超出了底部,也沒有辦法讓我看到更多內容。請問如何啓用滾動條? 我認爲「match_parent」有問題,但不知道如何解決。謝謝!Scrollview不顯示滾動條

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 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:orientation="vertical" 
    android:background="#ffffff"> 

     <TextView 
     android:id="@+id/textResult" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
      android:layout_below="@+id/buttonRecord" 
     android:layout_marginTop="16dp" 
     android:background="@drawable/back" 
     android:editable="true" 
     android:height="150dp" 
     android:text="" 
     android:enabled="false" 

     android:scrollbars="vertical" 
     style="@android:style/Widget.ScrollView" 
      android:layout_alignRight="@+id/buttonRecord" 
      android:layout_alignEnd="@+id/buttonRecord" 
      android:layout_alignLeft="@+id/buttonRecord" 
      android:layout_alignStart="@+id/buttonRecord" /> 

</RelativeLayout> 
+0

你的滾動視圖在哪裏?並改變問題標題...你試圖讓文本視圖滾動 –

+0

我認爲這是一個重複的問題[this](http://stackoverflow.com/questions/23873454/android-textview-scrollable) – nexus5x

回答

0

如果你想要滾動的內容,也許嘗試給它一個固定的高度?由於layout_height,此時高度設置爲wrap_content。如果你想有一個固定高度的TextView與滾動條垂直滾動, 定義XML佈局文件,我不認爲你應該在所有

0

使用android:height

<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:scrollbars="vertical" 
    android:text="@string/text_string" /> 

定義你的Java類文件:

TextView tv = (TextView) findViewById(R.id.textView); 
tv.setMovementMethod(new ScrollingMovementMethod());