【发布时间】:2016-09-01 23:55:24
【问题描述】:
我想在每次单击按钮时制作一个淡入淡出动画。 我开始只检查淡出,在第一次单击时,淡出似乎工作得很好。但是当我再次点击时,动画会从上到下淡出,使它看起来很糟糕并被剪掉了。
动画:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0"
android:toAlpha="0.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="1000" />
</set>
代码:
Animation fadeOut = AnimationUtils.loadAnimation(myActivity.this, R.anim.fade_out);
LinearLayout myBackground=(LinearLayout)findViewById(R.id.myBackground);
myBackground.setAnimation(fadeOut);
我错过了什么?谢谢!
【问题讨论】:
-
完成 setAnimation 后,您还需要启动动画...所以 myBackground.startAnimation
-
不敢相信...我没有意识到我使用的是 Set 而不是 Start! BTY 我不需要 Set 它只需要 startAnimation 就可以正常工作。谢谢你:)
-
@Tomik 我对此不熟悉,我需要做什么?