亲测可能。直接上代码。
测试机器: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 并不能滚动。不知道为什么。如果有知道原因的,或者有更好的写法的,欢迎大家热烈谈论。
分享到:
相关推荐
android TextView android TextView
android TextView 支持CSS样式
Android TextView 去掉自适应默认的fontpadding的实现方法 最近在项目中使用textview时发现在使用Android:layout_height=”wrap_content”这个属性设置后,textview会有默认的padding,也就是fontpadding。这样就会...
本文实例讲述了Android TextView实现垂直滚动效果的方法。分享给大家供大家参考,具体如下: 在TextView中,如果文本很长,可能需要实现垂直滚动显示文本的效果。这里需要在XML布局文件中为TextView设置如下几个属性...
Android textview 文字中间加上图片
MTextView,解决Android TextView提前换行的问题
android实现TextView文字部分渐变色;LinearGradientFontSpan SpannableString
主要介绍了Android TextView Marquee的应用实例详解的相关资料,这里说明使用方法及简单实例和注意实现,需要的朋友可以参考下
android textview 文字排版 换行
Android TextView 换行不对齐的问题
android textview图文混排支持GIF图 原生方式实现 glide支持
Android TextView显示html的demo ,演示如何在TextView上显示html效果,包括图片,
android TextView 折叠展开
Android TextView闪闪发光特效
可直接运行,方便直接添加到项目中 解决了android 加载Html页面只出现文字,图片加载不出来,直接显示小方块的问题
Android 文本类中字体颜色的改变,并可以相应点击事件
Android Textview实现文本间距
android textview 部分文本变色,点击可跳转到指定的链接