Android TextView 加滾動條

jjur4509 8年前發布 | 10K 次閱讀 Android開發 移動開發

來自: http://my.oschina.net/u/2320057/blog/608902


一.在<TextView>外面添加<ScrollView>標簽;

豎直滾動:使用標簽<ScrollView  ></ScrollView  >
水平滾動:使用標簽<horizontalscrollview></horizontalscrollview>
<ScrollView  
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content" >  
  
    <TextView  
        android:layout_width="fill_parent"  
        android:layout_height="wrap_content"  
        android:textSize="50dp"  
        android:text="a\na\na\na\na\na\na\na\na\na\na\na\na\na\n" />  
</ScrollView>

 

二.給TextView設置ScrollingMovementMethod

代碼中添加:
TextView textView = (TextView)findViewById(R.id.text_view);   
textView.setMovementMethod(ScrollingMovementMethod.getInstance()); 
//TextView.setMovementMethod(new ScrollingMovementMethod());
XML中配置:android:scrollbars="vertical"
<TextView  
    android:id="@+id/textview"  
    android:layout_width="fill_parent"  
    android:layout_height="wrap_content"  
    android:singleLine="false"  
    android:maxLines="5"  
    android:scrollbars="vertical"  
    />

 

三.使用Scroller來自定義TextView

 

 本文由用戶 jjur4509 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!