在“隐藏”活动上做动画

时间:2012-08-08 13:53:36

标签: android android-activity android-animation

我一直在尝试让一个活动在选择数据并准备好显示之前不显示:Prevent screen display until after fetching data

最后让它在主题的帮助下工作。

现在我有另一个问题。

我需要设置从一个Activity到下一个Activity的转换动画。 我知道如何使用overridePendingTransition但这在这里不起作用,因为当我想要做动画时我已经在目标Activity中。 我能看到另一个的唯一原因是因为当前的一个是透明的。

我在新的滑动中没有问题:

    View view = getLayoutInflater().inflate(R.layout.content_screen, null);
    view.startAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_in_right));
    setContentView(view);

但是,我想不出任何方法可以让旧版本滑出来。

任何想法?

1 个答案:

答案 0 :(得分:0)

创建“向左滑动”动画。然后调整新视图的动画,这样当动画开始时,您应用并启动另一个动画到另一个视图。如,

Animation animation = AnimationUtils.loadAnimation(context,
            R.anim.slide_in_right);
    animation.setDuration(TIME);
    animation.setAnimationListener(new AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
                        // TODO - Set and start other animation here
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }

        @Override
        public void onAnimationEnd(Animation animation) {

        }
    });

view.startAnimation(animation);

[编辑]

 // First, define and infalte the view that will be incoming
 View upcomingView = inflater.inflate(...);

 // Next, we'll set the animation up
 Animation animation = AnimationUtils.loadAnimation(context,
        R.anim.slide_in_right);
animation.setDuration(TIME);
animation.setAnimationListener(new AnimationListener() {

    @Override
    public void onAnimationStart(Animation animation) {
        Animation outAnimation = AnimationUtils.loadAnimation(context,
        R.anim.slide_out_left);
        upcomingView.startAnimation(outAnimation);
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }

    @Override
    public void onAnimationEnd(Animation animation) {

    }
});

currentView.startAnimation(animation); // This will start the animation defined above, which will also set and start the animation for the incoming object