您的位置:首页 > 其它

XML 实现 TextView的跑马灯效果

2014-05-18 11:43 295 查看
本文用XML直接实现TextView的跑马灯效果,代码如下:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:orientation="vertical" >

<TextView

android:id="@+id/marquee_tv"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="大解放了卡机的返利卡几点开房间卡洛斯的积分卡拉接受对方"

android:textColor="#FF0000"

android:singleLine="true"

android:ellipsize="marquee"

android:marqueeRepeatLimit="marquee_forever"

android:focusable="true"

android:focusableInTouchMode="true"/>

<TextView

android:id="@+id/no_marquee_tv"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="是快乐积分卡拉接受对方可拉伸积分卡拉就是疯狂地短发的空间按打开附件"

android:ellipsize="marquee"

android:singleLine="true"

android:marqueeRepeatLimit="marquee_forever"

android:focusable="true"

android:focusableInTouchMode="true"/>

</LinearLayout>

问题总结:

1.代码中的两个TextView,第一有跑马灯的效果,而第二个没有

原因:只有先设置android:singleLine="true"单行显示,再设置android:ellipsize="marquee"才有跑马灯效果

2.网上看了很多,都说只有设置android:layout_width为固定值,才能显示跑马灯效果,实际不然,正如本例所示,设置wrap_content其实也能实现
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: