我正在尝试使用启动画面来覆盖谷歌地图加载延迟(适用于Maps v2)。
我想在FrameLayout中使用一个ImageView,在几秒钟后淡出,并能够重写onAnimationEnd以隐藏启动画面的ImageView。
当没有延迟启动动画时,适当地调用onAnimationEnd。
问题在于当我尝试使用
我想在FrameLayout中使用一个ImageView,在几秒钟后淡出,并能够重写onAnimationEnd以隐藏启动画面的ImageView。
当没有延迟启动动画时,适当地调用onAnimationEnd。
new Animations().animateAlphaForLayout(splashLayout, 2000);
问题在于当我尝试使用
postDelayed
启动动画时,onAnimationEnd
根本没有被调用:splashLayout.postDelayed(new Runnable() {
@Override
public void run() {
new Animations().animateAlphaForLayout(splashLayout, 2000);
}
}, 3000);
Animations
类的代码如下:
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.LayoutAnimationController;
public class Animations {
public void animateAlphaForLayout(final ViewGroup viewGroup, int duration) {
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(1.0f, 0.0f);
animation.setRepeatCount(0);
animation.setFillAfter(true);
animation.setDuration(duration);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
viewGroup.setVisibility(View.GONE);
}
});
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(set, 0.0f);
viewGroup.setLayoutAnimation(controller);
}
}
有人知道在Android 2.3及更高版本(API 10+)上实现这个的方法吗?
谢谢!
onAnimationEnd()
根本没有被调用,还是因为你没有看到它的效果而得出结论它没有被调用? - class stackerpostDelayed
),一切都可以正常工作 - 即使是onAnimationEnd
。 - mirel.cocosila