GridView 中TextView的跑马灯效果

来源:互联网 发布:ubuntu 垃圾箱路径 编辑:程序博客网 时间:2024/04/29 08:50

 

[html] view plaincopy
  1. <TextView  
  2.  android:id="@+id/game_info_gname"   
  3. android:layout_width="78dp"   
  4. android:layout_height="wrap_content"   
  5. android:focusable="true"   
  6. android:focusableInTouchMode="true"   
  7. android:marqueeRepeatLimit="marquee_forever"   
  8. android:ellipsize="marquee"   
  9. android:singleLine="true"   
  10. android:textSize="15sp"   
  11. android:textStyle="bold" />  


 

如果TextView跑马灯效果没有实现的童鞋,注意一下  android:focusable="true"   android:focusableInTouchMode="true" 

加上这两个属性然后TextView有了华丽丽的跑马灯效果,但是当你兴冲冲的把他加入到GridView中,你会发现,不仅跑马灯效果没有了,而且因为设置了android:focusable属性,会让GridView没法点击了。下边是解决办法:其实很简单:重写TextView的isFocused方法

 

[java] view plaincopy
  1. public class mTextView extends TextView {  
  2.     //构造方法了  
  3.         ......  
  4.         ......  
  5.     public boolean isFocused() {  
  6.         return true;  
  7.     }  
  8. }  


然后把这个TextView 扔到你的GridView 的item中
   

[html] view plaincopy
  1. <org.cs.views.mTextView   
  2.             android:layout_width="wrap_content"  
  3.             android:layout_height="wrap_content"  
  4.             android:focusableInTouchMode="true"   
  5.             android:marqueeRepeatLimit="marquee_forever"  
  6.             android:ellipsize="marquee"  
  7.             android:singleLine="true"  
  8.             android:scrollHorizontally="true"  
  9.             android:textSize="15sp"  
  10.             android:textStyle="bold"  
  11.             />