如何在Android中按顺序(逐个)运行两个或多个动画?
我想先从1运行alpha动画到0,然后再运行alpha动画从0到1,但是不起作用! 这是我的代码:如何在Android中按顺序(逐个)运行两个或多个动画?,android,android-animation,Android,Android Animation,我想先从1运行alpha动画到0,然后再运行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); TextView iv_1 = findViewById(R.id.tv_1
TextView iv_1 = findViewById(R.id.tv_1);
AnimationSet animSet = (AnimationSet) AnimationUtils.loadAnimation(this, R.anim.alpha_set);
iv_1.setAnimation(animSet);
TextView iv_1 = findViewById(R.id.tv_1);
AnimationSet animSet = (AnimationSet) AnimationUtils.loadAnimation(this, R.anim.alpha_and_scale);
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>
<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>
alpha_和_scale.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>
<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>
为什么?我尝试了以下方法,它对我有效
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:duration="2000"
android:fromAlpha="1"
android:toAlpha="0"
android:repeatMode="reverse"
android:repeatCount="1"/>
</set>
希望这对您有所帮助。您可以使用动画侦听器作为解决方法。或者只需使用动画重复计数(2)和重复模式(反转)即可重复动画谢谢您的帮助!“但是它不能解决我的问题,我看不出它不能解决的唯一原因。”VladyslavMatviienko你能试着在你的设备上运行我的代码吗?