* 《控件篇——TextView文字显示不全,跑马灯效果显示》*
在用TextView 显示文字的时候,由于文字过长,会导致TextView分行显示文字,但是在复杂的界面布局不允许TextView占用太多的空间,只能显示一行,所以当设置 TextView属性为 android:singleLine 时会强制让TextView只显示一行,多余的文字会从后边省略,当设置TextView的几个属性之后就会使得文字轮换展示。实现跑马灯效果。
<TextView android:layout_width="200dp"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:ellipsize="marquee"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"
android:focusableInTouchMode="true"
android:scrollHorizontally="true"
android:text="这才是真正的文字跑马灯效果"
>
</TextView>
- android:focusable=”true” 指TextView在得到焦点后触发事件
- android:ellipsize=”marquee” 设置文字过长时该控件如何显示。“start”省略部分在开头,“end”省略部分在结尾,“middle”省略部分在中间。“marquee”以跑马灯(动画横向显示)效果展示
- android:marqueeRepeatLimit=”marquee_forever” 设置ellipsize指定marquee情况下重复滚动次数,marquee_forever表示无限滚动
- android:focusableInTouchMode=”true” 指不用获取焦点,就触发事件,一运行就触发。
- android:scrollHorizontally=”true” 设置文字超出TextView的宽度情况下,是否出现横拉条。