android textview 垂直滾動and水平跑馬燈

垂直滾動的話就挺簡單的。當然了不是自動的垂直滾動。如果是自動的垂直滾動的話還需要自定義。所以如果有需求需要textview 可以垂直滾動的話,那你來這裏就對了。

直接貼 代碼。就是這麼任性。

<TextView  
        android:id="@+id/textview"  
        android:layout_width="100dp"  
        android:layout_height="wrap_content"  
        android:maxLines="3"  
        android:background="#FFF"  
        android:textColor="#000"  
        android:textSize="20dp"  
        android:layout_margin="10dp"  
        android:text="23423423423423423423423423423432     2344444444444       23432423       234234 
        
        234234234
        234234
        234234
                2342342   
                
                234234"  
        /> 
請大家忽略 我那一串 測試的文字。 因爲這樣會顯得我的x格 很低。(雖然確實很低咳咳 偷笑) 然而這樣是不行的你會發現 這就是一個普通的xml 的textview 啊  。對 你發現的很對。其實真相只有一個 就是這句代碼

tv.setMovementMethod(ScrollingMovementMethod.getInstance());

加上他 你就可以滾動了。不相信嘛。不相信 你可以試試

跑馬燈效果如何實現 貼代碼 too 

 <TextView  
        android:id="@+id/textview"  
        android:layout_width="100dp"  
        android:layout_height="wrap_content"  
        android:maxLines="3"  
        android:background="#FFF"  
        android:textColor="#000"  
        android:textSize="20dp"  
        android:layout_margin="10dp"  
        android:text="23423423423423423423423423423432     2344444444444       23432423       234234 
        234234234
        234234
        234234
        2342342   
        234234"  
          android:ellipsize="marquee"
          android:fadingEdge="horizontal"
          android:focusable="true"
          android:focusableInTouchMode="true"
          android:marqueeRepeatLimit="marquee_forever"
          android:scrollHorizontally="true"
          android:singleLine="true"
        /> 
標紅的是關鍵配置上就可以水平滾動了。marqueeRepeatLimit 是滾動次數。forever 是無限滾動

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章