【问题标题】:Chaining animation of a TextSwitcher and an ImageSwitcherTextSwitcher 和 ImageSwitcher 的链接动画
【发布时间】: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));
        }
    }

有没有更短的方法来链接对象动画?

【问题讨论】:

标签: android animation chain imageswitcher textswitcher


【解决方案1】:

您应该将第二个动画放在第一个动画回调中。 下面是工作代码。

$(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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多