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;  }   }

转载于:https://www.cnblogs.com/yckv/p/4805981.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值