TextView 滾動

文字左右滾動三個屬性:
         android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"


大量文本內容滾動:
TextView自己也可以實現多行滾動的,畢竟 ScrollView必須只能有一個直接的子類佈局。只要在layout中簡單設置幾個屬性就可以輕鬆實現。
  <TextView
    android:id="@+id/tvCWJ"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="vertical"  <!--垂直滾動條 -->
    android:singleLine="false"      <!--實現多行 -->
    android:maxLines="15"            <!--最多不超過15行 -->
    android:textColor="#FF0000"
    />

爲了讓TextView動起來,還需要用到TextView的setMovementMethod方法設置一個滾動實例,代碼如下
TextView tv  = (TextView)findViewById(R.id.tvCWJ); 
tv.setMovementMethod(ScrollingMovementMethod.getInstance()); 
 

 

發佈了18 篇原創文章 · 獲贊 1 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章