android - TextViews 在 Android 4 上只做一次动画

标签 android animation textview backwards-compatibility layout-animation

我有一个包含多个按钮和两个 TextView 的布局 (RelativeLayout)。对于每次信息更改,我都会淡出所有 View ,更新信息,然后淡入 View 。我为此使用布局动画。

非常奇怪的是 TextView 只能动画一次。它们正确地淡入淡出一次,然后就不再动画了。另一方面,按钮继续保持动画效果。

另一个可能很奇怪的事情是我在 android 2.3.x 上没有遇到这个问题,但是在 android 4.0.x 上。

我可以通过在淡入后清除 TextView 上的动画来解决这个问题,但它看起来不太好,因为它们仍然没有淡入。

我曾尝试在淡入之前清除 TextView 上的动画,但无济于事。我还尝试了 list 中 targetSdkVersion 属性的不同设置,但没有任何结果。

动画淡入(淡出类似):

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="750" 
    android:fillAfter="true" 
    android:fromAlpha="0.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:toAlpha="1.0" 
/>

动画代码(每次布局淡入时运行):

// Set listener.
viewGroup.setLayoutAnimationListener(listener);

// Load animation.
final Animation fadeIn = AnimationUtils.loadAnimation(context, R.anim.fade_in);

// Create and start animation controller.
final LayoutAnimationController animController = new LayoutAnimationController(fadeIn);
viewGroup.setLayoutAnimation(animController);
animController.setAnimation(fadeIn);
animController.setDelay(FADE_IN_DELAY + extraDelay);
animController.setOrder(LayoutAnimationController.ORDER_REVERSE);
animController.start();

有人知道吗? Buttons 和 TextViews 之间是否存在某种特定于动画的区别? Android 4 中是否有任何破坏向后兼容性的动画更改?

谢谢!

最佳答案

只有当 View 组对其子项进行布局时才会出现布局动画 - 根据 [LayoutAnimationController][1] 文档,为每个子项播放相同的动画,但开始时间不同 - 它是通常用于例如ListViewGridView 为项目的入口设置动画。

更新内容时,通常不会播放动画。您需要使用 View.startAnimation(Animation)View.clearAnimation() 来确保每次更新内容时都播放动画。

关于android - TextViews 在 Android 4 上只做一次动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14181325/

相关文章:

android - JTwitter for android 中的 setAPIRootUrl 是什么?

objective-c - 带有动画的 iOS 方法调用,完成时执行操作?

animation - Firefox 和 IE 中的 css 关键帧动画

java - Android TextView 上标

相当于 textCapSentences 的 android TextView

android - 直接访问android通知?

android - 从 Android 应用程序打开 Twitter 帐户

Android BLE 启用通知

css - 让 translateX 使用视口(viewport)宽度而不是元素宽度

Android TextView文本分割系统