【发布时间】:2018-05-18 09:44:04
【问题描述】:
我想先运行从1到0的alpha动画,然后之后我想运行alpha 动画 从 0 到 1,但它不起作用! 这是我的代码:
TextView iv_1 = findViewById(R.id.tv_1);
AnimationSet animSet = (AnimationSet) AnimationUtils.loadAnimation(this, R.anim.alpha_set);
iv_1.setAnimation(animSet);
alpha_set.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
>
<alpha android:duration="2000"
android:fromAlpha="1"
android:toAlpha="0"
/>
<alpha android:duration="2000"
android:fromAlpha="0"
android:toAlpha="1"
android:startOffset="2000"/>
</set>
但是当我想先运行 alpha 动画,然后运行 缩放动画,它效果很好!以下是我的代码:
TextView iv_1 = findViewById(R.id.tv_1);
AnimationSet animSet = (AnimationSet) AnimationUtils.loadAnimation(this, R.anim.alpha_and_scale);
iv_1.setAnimation(animSet);
alpha_and_scale.xml
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<alpha android:duration="2000"
android:fromAlpha="0"
android:toAlpha="1"
/>
<scale android:startOffset="2000"
android:pivotX="50%"
android:pivotY="50%"
android:fromXScale="0.8"
android:toXScale="1"
android:fromYScale="1"
android:toYScale="1"
android:duration="2000"/>
</set>
为什么?
【问题讨论】:
-
您可以使用动画侦听器作为解决方法。或者只是使用动画重复计数 (2) 和重复模式 (reverse) 来重复动画
-
感谢您的帮助!但它不能解决我的问题
-
我看不出它不能这样做的单一原因。
-
@VladyslavMatviienko 你能尝试在你的设备上运行我的代码吗?