android 讓 TextView 自帶滾動條

weixin_34262482發表於2012-08-21

一、Xml程式碼

  1. <TextView  
  2.     android:id="@+id/textview"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="wrap_content"  
  5.     android:singleLine="false"  
  6.     android:maxLines="5"  
  7.     android:scrollbars="vertical"  
  8.     />

二、還需要在程式碼中設定 TextView 相應的方法

  1. TextView textView = (TextView)findViewById(R.id.text_view);   
  2. textView.setMovementMethod(ScrollingMovementMethod.getInstance()); 

好了,大功告成。

相關文章