在Android 4.0.3中设置textview淡入淡出

发布于 2025-01-05 17:53:11 字数 476 浏览 2 评论 0原文

我刚刚尝试在Android 4.0.3中实现TextView的淡入淡出效果;然而,它不起作用。

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

此代码适用于 2.3.7 及以下版本,但不适用于 4.0.3。 我想知道为什么会这样?以及如何为TextView制作淡入淡出效果?

我的问题与此相同:http://groups.google。 com/group/android-developers/browse_thread/thread/97131b20de8b2ebd ,但还没有答案。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦途 2025-01-12 17:53:11

虽然有点晚了,但这可能会对有同样问题的人有所帮助。

我在不同的手机上遇到过这个问题,它可能来自于:

  • 在Android 4.0.x上,似乎TextView必须是可聚焦的,否则淡入淡出效果将不起作用。所以尝试添加这个:

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

  • 如果这不起作用,您可以尝试 android:lines="1",但我认为 android:singleLine="true"(已弃用)效果更好

  • 有时,你需要以编程方式调用 setSelected(true) textView 获得淡入淡出效果。请检查此链接:有没有办法制作椭圆形="marquee" 总是滚动?

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?

时光是把杀猪刀 2025-01-12 17:53:11

从 API 级别 14 开始,fadingEdge 已被弃用并被忽略,因此为了使淡入淡出边缘在 Android 4.0.3 上工作,您必须使用 requiresFadingEdge 代替。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文