我有一个带有TextSwitcher和ImageSwitcher对象的android studio项目,它们已经设置好了,并且(同时)可以完美地工作。问题是,我希望首先执行TextSwitcher的动画,然后是ImageSwitcher的动画(在TextSwitcher动画结束之后)。我尝试将AnimationListener添加到TextSwitcher中,并在AnimationListener的“onAnimationEnd”方法中更改ImageSwitcher的图像,但不起作用。
有谁有什么想法吗?任何帮助都将不胜感激!
编辑:为了让动画监听程序工作,下面是代码片段:
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));
}
}有没有一种更短的方法来链接对象动画?
发布于 2016-07-02 07:04:57
你应该把第二个动画放在第一个动画回调中。下面是工作代码。
$(function(){
$('.textSwitcher').show(1000, function(){
$('.imageSwitcher').show(1000);
});
}).textSwitcher, .imageSwitcher {
width: 100px;
height: 100px;
display: none;
}
.textSwitcher {
background: red;
}
.imageSwitcher {
background: blue;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="textSwitcher"></div>
<div class="imageSwitcher"></div>
https://stackoverflow.com/questions/38154814
复制相似问题