android 跑马灯

                         跑马灯效果

layout布局代码

<!--android:ellipsize 设置文字过长时,该控件是如何显示的呢?

start—省略号显示在开头 end—省略号显示在结尾 middle—省略号显示在中间

marquee—以跑马灯的方式显示 -->

<!--无数次的跑动-->

android:marqueeRepeatLimit=”marquee_forever”

<!--触摸时获得焦点-->

android:focuseableTouchMode=”true”

<!--使文本单行显示-->

android:singleLine="true"

<!--以包名调用MyTextView中的方法 -->

<!--android:layout_below="@+id/textview"把该组件的底部置于给定ID的组件之下(PS:把当前组件放在给定ID组件的下面) -->

<!--android:layout_above="@+id/textview"把该组件的底部置于给定ID的组件之上(PS:把当前组件放在给定ID组件的上面) -->

<

cn.androidstudy.pmd.MyTextView

android:id="@+id/textview"        

android:layout_width="wrap_content"        

android:layout_height="wrap_content"        

android:singleLine="true"        

android:ellipsize="marquee"        

android:focusableInTouchMode="true"        

android:focusable="true"        

android:text="@string/hello_world" />         

<cn.androidstudy.pmd.MyTextView

android:id="@+id/textview1"        

android:layout_width="wrap_content"        

android:layout_height="wrap_content"        

android:singleLine="true"        

android:ellipsize="marquee"        

android:focusableInTouchMode="true"        

android:focusable="true"        

android:layout_below="@+id/textview"        

android:text="@string/hello_world" />           

<cn.androidstudy.pmd.MyTextView        

android:id="@+id/textview2"        

android:layout_width="wrap_content"        

android:layout_height="wrap_content"        

android:singleLine="true"        

android:ellipsize="marquee"        

android:focusableInTouchMode="true"        

android:focusable="true"        

android:layout_below="@+id/textview1"        

android:text="@string/hello_world" />

多个跑马灯的class文件

package cn.androidstudy.pmd;

import android.content.Context;

import android.util.AttributeSet;

import android.widget.TextView;

public class MyTextView extends TextView{

 public MyTextView(Context context) {   

super(context);   // TODO Auto-generated constructor stub  }

 public MyTextView(Context context, AttributeSet attrs, int defStyle) {

  super(context, attrs, defStyle);   // TODO Auto-generated constructor stub  }

 public MyTextView(Context context, AttributeSet attrs) {   

super(context, attrs);   // TODO Auto-generated constructor stub  }

 public boolean isFocused(){   

return true;  }   }

posted @ 2015-09-14 00:51  星晨-XC  阅读(188)  评论(0编辑  收藏  举报