android用TextView實現跑馬燈效果

來源:互聯網
上載者:User

今天搞啦很久,其實很簡單,就加幾個屬性就可以啦!

圖如下 :

 

 

 

有的說要重寫TextView方法,有的說要設定固定長度,但是我沒重寫也沒有設定固定長度也弄出來啦!跑在2.3.3的手機上面。就是不知道其他地方能不能實現這種效果!

 

代碼如下:(其他地方代碼沒什麼關係)

  1.   <TextView  
  2. android:layout_width="fill_parent"  
  3. android:layout_height="wrap_content"    
  4. android:id="@+id/notice"    
  5. android:background="@color/black20"     
  6. android:text="他們說這裡是要放廣告的,就是看看能不能動啊!長點...!!!!..."    
  7. android:ellipsize="marquee"    
  8. android:gravity="center"    
  9. android:textStyle="bold"    
  10. <span style="color:#ff0000;">android:focusable="true"    
  11. android:marqueeRepeatLimit="marquee_forever"    
  12. android:focusableInTouchMode="true"    
  13. android:scrollHorizontally="true"    
  14. android:singleLine="true"  </span>  
  15. android:textSize="@dimen/activity_Textsize15_4.0"    
  16. />    
  17.    

 

要注意的就是內容一點要夠長才會滾動,不然就不會滾動。 紅色標記的代碼是關鍵代碼。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.