BloggerAds

2011年8月3日 星期三

TextView實現多行滾動

TextView實現多行滾動  


==============================================================


XML部分



<TextView android:id="@+id/textView1" 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:scrollbars="vertical" (垂直滾動條)
    android:singleLine="false"    (實現多行)
    android:maxLines="5"           (最多不超過5行)
    android:width="250px"         (寬度)

    android:text="TextView" 
    android:layout_alignParentTop="true" 
    android:layout_alignLeft="@+id/imageView_back" 
    android:layout_marginTop="59dp"></TextView>



重要的是紅色的部分 後面註解要去掉


程式部分要加入下面紅色的部分  就OK囉


tv=(TextView) findViewById(R.id.textView1);


 


tv.setMovementMethod(ScrollingMovementMethod.getInstance());