我想要一个View
最初是不可见的,当我按下一个按钮时,它会随着动画的淡入而变得可见。我正在使用AlphaAnimation
褪色效果。问题是,如果我使视图不可见,则无法看到动画。
问问题
65581 次
3 回答
126
假设您的 res\anim\ 文件夹中有一个ImageView
命名imageView
的动画文件:your_fade_in_anim.xml
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Animation fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.your_fade_in_anim);
// Now Set your animation
imageView.startAnimation(fadeInAnimation);
你的 XML
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="[duration (in milliseconds)]"
android:repeatCount="infinite" />
</set>
用您的实际持续时间替换括号。
于 2011-02-23T11:49:40.300 回答
26
为动画提供一个AnimationListener
,并在动画开始后立即使视图可见。
http://developer.android.com/reference/android/view/animation/Animation.AnimationListener.html
于 2011-02-23T11:37:56.623 回答
3
而不是无限重复计数和隐藏/查看您的视图,我建议不要重复动画并最初从设置为最大值的 alpha 通道开始。然后你可以使用:
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="[duration (in milliseconds)]"
android:repeatCount="0" />
</set>
你完成了。不需要监听器,隐藏或显示。一样简单。
于 2014-10-16T13:43:53.213 回答