`
yhz61010
  • 浏览: 549287 次
  • 来自: -
博客专栏
63c13ecc-ef01-31cf-984e-de461c7dfde8
libgdx 游戏开发
浏览量:11915
社区版块
存档分类
最新评论

[原创] 开启 Android TextView Marquee

阅读更多
亲测可能。直接上代码。
测试机器:XiaoMi 2S Android 5.0

<TextView
    android:id="@+id/toolbar_title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:fadingEdge="none"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:freezesText="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:singleLine="true"
    android:scrollHorizontally="true"
    android:textColor="#fff"
    android:textSize="16sp" />

mToolbarTitle.setSelected(true);

说明:
XML 中以下几行是必须的:
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"

最后别忘了,JAVA 中还需要调用 TextView 的 setSelected(true) 方法。

特别注意:
目前发现,android:singleLine="true" 这种写法需要已经被废弃了,但是目前只能这么写 Marquee 才能生效。如果换成最新的写法 android:maxLines="1",你会发现,Marquee 并不能滚动。不知道为什么。如果有知道原因的,或者有更好的写法的,欢迎大家热烈谈论。
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics