android 实现TextView实现跑马灯形式的字体

        

        在android中,如何让TextView实现跑马灯效果呢?今天我们就来讲讲如何实现吧。

        <TextView
            android:id="@+id/t1"
            android:layout_width="200dp"
            android:layout_height="wrap_content" 
            android:ellipsize="marquee"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollX="2dp"
            android:singleLine="true"
            android:text="此处为文本显示区域的宽度此值必须比你的文本宽度要小否则是没有效果的"
            android:textColor="#ff00ff00"  >
        </TextView>

        如何只是这样,不会出现跑马灯效果,我们还要处理一下。

        TextView t= (TextView) findViewById(R.id.t1);  

        t.setTextSize(30);

        t.setHorizontallyScrolling(true);

        t.setFocusable(true);

        t.setFocusableInTouchMode(true);

        因为我们的TextView就能聚焦,才能滚动效果。效果如图一,图二所示:


           (图一)      (图二)


         如果我们不在代码中进行聚焦,我们也可以在布局文件中设置:

         <TextView
            android:id="@+id/t1"
            android:layout_width="200dp"
            android:layout_height="wrap_content" 
            android:ellipsize="marquee"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollX="2dp"
            android:singleLine="true"
            android:text="此处为文本显示区域的宽度此值必须比你的文本宽度要小否则是没有效果的"
            android:textColor="#ff00ff00" 
            android:clickable="true"  
            android:focusable="true"  
            android:focusableInTouchMode="true">


    -_- @a little a day


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值