【发布时间】:2016-07-01 22:56:21
【问题描述】:
我有一个 android studio 项目,其中包含一个 TextSwitcher 和一个 ImageSwitcher 对象,它们已经设置好并且可以正常工作(同时)。 问题是,我希望首先执行 TextSwitcher 的动画,然后是 ImageSwitcher 的动画(在 TextSwitcher 动画结束之后)。 我尝试将 AnimationListener 添加到 TextSwitcher 并在 AnimationListener 的 'onAnimationEnd' 方法中更改 ImageSwitcher 的图像,但没有成功。
有人有什么想法吗? 任何帮助将不胜感激!
编辑: 设法让动画侦听器工作,这是代码的 sn-p:
private void loadPosts() {
Post post = posts.get(currentPost);
//..
Animation outAnimation = AnimationUtils.loadAnimation(this, R.anim.fade_out);
outAnimation.setAnimationListener(new NextPostAnimation(post));
textSwitcher.setOutAnimation(outAnimation);
textSwitcher.setText("some text");
}
private class NextPostAnimation implements Animation.AnimationListener {
Post post;
NextPostAnimation (Post post) {
super();
this.post = post;
}
@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) {
imageSwitcher1.setImageDrawable(new BitmapDrawable(getResources(), post.image1));
}
}
有没有更短的方法来链接对象动画?
【问题讨论】:
-
考虑包含您的代码以提供上下文。见:stackoverflow.com/help/mcve
标签: android animation chain imageswitcher textswitcher