滚动跑马灯问题

实现效果主要代码段(运行在模拟器上就能看到效果)

android:ellipsize="marquee"

android:singleLine="true"
        android:marqueeRepeatLimit="marquee_forever"

通过此段代码则可实现跑马灯效果,然而此处,仅有这段代码只能实现一处跑马灯效果,并不能实现多行都能进行。

看下面这段代码以及一些基本设置

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/background_light"
    android:orientation="vertical" >
    
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/text_view_long"
        android:textColor="@android:color/holo_orange_dark"
        android:textSize="20sp"


        android:maxEms="5"              <!--设置显示的字数-->
        android:ellipsize="marquee" <!--  设置显示效果 -->
        android:focusable="true" <!--确定是否能进行焦点操作,通过点击将效果移至点击处-->
        android:singleLine="true" <!-- 设置单行运行  -->
        android:marqueeRepeatLimit="marquee_forever"            <!--   设置次数    -->
        android:focusableInTouchMode="true"
        
        />


    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/text_view_long"
        android:textColor="@android:color/holo_orange_dark"
        android:textSize="20sp"
        
        android:maxEms="5"
        android:ellipsize="marquee"
        android:focusable="true"
        android:singleLine="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:focusableInTouchMode="true"
        
        />
</LinearLayout>

<!--    -----------------------------------------------------  -->


若是想进行多行同时进行跑马灯效果,则可通过下面代码实现

xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    

<!--   com.example.ui.widget.Marquee_Test1    由包名+类名组成  -->


    <com.example.ui.widget.Marquee_Test1 android:layout_width="wrap_content"     
        android:layout_height="wrap_content"
        android:text="@string/text_view_long"
        android:textColor="@android:color/holo_orange_dark"
        android:textSize="20sp"
        
        android:maxEms="5"
        android:ellipsize="marquee"
       
        android:singleLine="true"
        android:marqueeRepeatLimit="marquee_forever"
       
        
        />


    <com.example.ui.widget.Marquee_Test1 android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/text_view_long"
        android:textColor="@android:color/holo_blue_bright"
        android:textSize="20sp"
        android:layout_marginTop="20dp"
        android:maxEms="5"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:marqueeRepeatLimit="marquee_forever"
       
        
        />
</LinearLayout>

Java文件://通过继承Textview来重写isFocused实现,

public class Marquee_Test1 extends TextView{


public Marquee_Test1(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public Marquee_Test1(Context context, AttributeSet attrs) {
 super(context, attrs);
}
public Marquee_Test1(Context context, AttributeSet attrs, int defStyle) {
 super(context, attrs, defStyle);
}

@Override
public boolean isFocused() {
// TODO Auto-generated method stub
return true; //始终返回true则可实现滚动效果了
}
}

最后关于注册实现则同其他实现方法相同,需另建类继承activity父类实现,Marquee_Test1类只是负责多行滚动效果处理。


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值