TextView中的跑马灯不动

转自:http://blog.csdn.net/qq435757399/article/details/8811098


今天用到AndroidTextView的跑马灯效果,在原项目的Layout布局中加了一个跑马灯文本,奇了怪了,文字能出现就是不给我跑起来,又重建了个项目测试,它又能跑了!活见鬼了!!!!

1.下面是测试项中的布局文件:


[html]  view plain copy
  1. <span style="font-size:14px;"><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent" >  
  5.   
  6.     <TextView  
  7.         android:id="@+id/indexgallerytv"  
  8.         android:layout_width="200dip"  
  9.         android:layout_height="wrap_content"  
  10.         android:layout_centerHorizontal="true"  
  11.         android:layout_centerVertical="true"  
  12.         android:ellipsize="marquee"  
  13.         android:focusable="true"  
  14.         android:focusableInTouchMode="true"  
  15.         android:gravity="left|center"  
  16.         android:marqueeRepeatLimit="marquee_forever"  
  17.         android:paddingLeft="20dip"  
  18.         android:paddingRight="20dip"  
  19.         android:textColor="#000000"  
  20.         android:scrollHorizontally="true"  
  21.         android:text="多少次迎着冷眼与嘲笑,从没有放弃过心中的理想,一刹那恍惚,若有所失的感觉,不知不觉已变淡,心里爱"  
  22.           
  23.         android:textSize="20dip" />  
  24.   
  25. </RelativeLayout></span>  




2.下面是加到的项目的布局文件中:(此处为错误的布局;下面贴有正确的布局)


[html]  view plain copy
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:background="#ffffff" >  
  6.   
  7.     <include  
  8.         android:id="@+id/title"  
  9.         android:layout_alignParentTop="true"  
  10.         layout="@layout/main_title" />  
  11.   
  12.     <LinearLayout  
  13.         android:id="@+id/top_layout"  
  14.         android:layout_width="fill_parent"  
  15.         android:layout_height="120dip"  
  16.         android:layout_below="@+id/title"  
  17.         android:layout_margin="5dip"  
  18.         android:background="@drawable/integral"  
  19.         android:text="@string/hello_world"  
  20.         tools:context=".MainActivity" />  
  21.   
  22.     <GridView  
  23.         android:id="@+id/grid_view"  
  24.         android:layout_width="fill_parent"  
  25.         android:layout_height="wrap_content"  
  26.         android:layout_below="@+id/top_layout"  
  27.         android:layout_marginLeft="1dip"  
  28.         android:layout_marginRight="1dip"  
  29.         android:cacheColorHint="#00000000"  
  30.         android:columnWidth="5dip"  
  31.         android:numColumns="3" >  
  32.     </GridView>  
  33.   
  34.    <TextView  
  35.         android:id="@+id/indexgallerytv"  
  36.         android:layout_width="200dip"  
  37.         android:layout_height="wrap_content"  
  38.        android:layout_alignParentBottom="true"  
  39.         android:ellipsize="marquee"  
  40.         android:focusable="true"  
  41.         android:focusableInTouchMode="true"  
  42.         android:gravity="left|center"  
  43.         android:marqueeRepeatLimit="marquee_forever"  
  44.         android:paddingLeft="20dip"  
  45.         android:paddingRight="20dip"  
  46.         android:textColor="#000000"  
  47.         android:scrollHorizontally="true"  
  48.         android:text="多少次迎着冷眼与嘲笑,从没有放弃过心中的理想,一刹那恍惚,若有所失的感觉,不知不觉已变淡,心里爱"  
  49.           
  50.         android:textSize="20dip" />  
  51.   
  52. </RelativeLayout>  

3.后来网上查了下  巴士上面有人给了一个Demo,以上的问题主要是TextView不能获取焦点,不能跑起来,现在重写一下TextView中的方法,让它不获取焦点一样也可以跑起来


[java]  view plain copy
  1. package com.jun.widget;  
  2.   
  3. import android.content.Context;  
  4. import android.graphics.Rect;  
  5. import android.util.AttributeSet;  
  6. import android.widget.TextView;  
  7.   
  8. public class MarqueeText extends TextView {  
  9.     public MarqueeText(Context con) {  
  10.       super(con);  
  11.     }  
  12.   
  13.     public MarqueeText(Context context, AttributeSet attrs) {  
  14.       super(context, attrs);  
  15.     }  
  16.     public MarqueeText(Context context, AttributeSet attrs, int defStyle) {  
  17.       super(context, attrs, defStyle);  
  18.     }  
  19.     @Override  
  20.     public boolean isFocused() {  
  21.     return true;  
  22.     }  
  23.     @Override  
  24.     protected void onFocusChanged(boolean focused, int direction,  
  25.        Rect previouslyFocusedRect) {    
  26.     }  
  27.     }  

4.我项目中的布局:


[html]  view plain copy
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:background="#ffffff" >  
  6.   
  7.     <include  
  8.         android:id="@+id/title"  
  9.         android:layout_alignParentTop="true"  
  10.         layout="@layout/main_title" />  
  11.   
  12.     <LinearLayout  
  13.         android:id="@+id/top_layout"  
  14.         android:layout_width="fill_parent"  
  15.         android:layout_height="120dip"  
  16.         android:layout_below="@+id/title"  
  17.         android:layout_margin="5dip"  
  18.         android:background="@drawable/integral"  
  19.         android:text="@string/hello_world"  
  20.         tools:context=".MainActivity" >  
  21.     </LinearLayout>  
  22.   
  23.     <GridView  
  24.         android:id="@+id/grid_view"  
  25.         android:layout_width="fill_parent"  
  26.         android:layout_height="wrap_content"  
  27.         android:layout_above="@+id/pao"  
  28.         android:layout_below="@+id/top_layout"  
  29.         android:layout_marginLeft="1dip"  
  30.         android:layout_marginRight="1dip"  
  31.         android:cacheColorHint="#00000000"  
  32.         android:columnWidth="5dip"  
  33.         android:numColumns="3" >  
  34.     </GridView>  
  35.   
  36.     <com.jun.widget.MarqueeText  
  37.         android:id="@+id/pao"  
  38.         android:layout_width="200dip"  
  39.         android:layout_height="wrap_content"  
  40.         android:layout_alignParentBottom="true"  
  41.         android:ellipsize="marquee"  
  42.         android:focusable="true"  
  43.         android:focusableInTouchMode="true"  
  44.         android:gravity="left|center"  
  45.         android:marqueeRepeatLimit="marquee_forever"  
  46.         android:paddingLeft="20dip"  
  47.         android:paddingRight="20dip"  
  48.         android:scrollHorizontally="true"  
  49.         android:text="多少次迎着冷眼与嘲笑,从没有放弃过心中的理想,一刹那恍惚,若有所失的感觉,不知不觉已变淡,心里爱"  
  50.         android:textColor="#000000"  
  51.         android:textSize="20dip" />  
  52.   
  53. </RelativeLayout>  

经过以上修改   跑马灯就跑起来了!哈哈
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值