Set textview fading in Android 4.0.3

你。 提交于 2020-01-22 21:01:48

问题


I've just tried to implement the fade effect for TextView in Android 4.0.3; however, it doesn't work.

fadingEdge="horizontal"
singleLine="true"
ellipsize="marquee"

This code works perfectly for 2.3.7 and below, but not working for 4.0.3. I'm wondering why is that so? and how to make fade effect for TextView?

My question is the same as this one: http://groups.google.com/group/android-developers/browse_thread/thread/97131b20de8b2ebd , but no answer yet.


回答1:


It is a bit late, but that may help people who have the same question.

I have had this problem on different phones, and it could come from that :

  • on Android 4.0.x, it seems that the TextView have to be focusable, otherwise fade effect won't work. So try adding this :

    android:focusable="true" android:focusableInTouchMode="true"

  • if that does not work, you could try android:lines="1", but i think that android:singleLine="true", which is deprecated, works better

  • sometimes, you need to programmatically call setSelected(true) on the textView to get the fade effect. Please check this link : Is there a way to make ellipsize="marquee" always scroll?




回答2:


As of API level 14 fadingEdge is deprecated and ignored so in order to make fading edge work on Android 4.0.3 you must use requiresFadingEdge instead.



来源:https://stackoverflow.com/questions/9307644/set-textview-fading-in-android-4-0-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!