2012-08-08 82 views
0

我一直在努力尝试,直到数据已被选中获得一个活动不显示,并准备用于显示动画:Prevent screen display until after fetching data做的“隐藏”活动

终于它与主题的援助工作。

现在我有另一个问题。

我需要动画从一个活动到下一个活动的过渡。 我知道如何使用overridePendingTransition,但这不会在这里工作,因为我已经在目标活动,当我想要做动画。 我可以看到另一个的唯一原因是因为当前的透明。

我没有问题,在新的一个滑动:

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

不过,我想不出任何办法让旧滑出。

任何想法的人?

回答

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 
+0

问题是,将被应用到新的视图。另一个视图甚至不在当前的Activity中,所以如何获得它的句柄才能使其动画化? – theblitz 2012-08-08 14:24:33

+0

所以你需要定义两个单独的视图。一个视图,我们将其称为currentView,需要具有上述定义的动画。这将使它开始滑向右侧。那么你需要另一个视图(已经膨胀),我将称之为即兴视图。在“onAnimationStart”中,您需要将左侧动画中的幻灯片应用于,然后为其调用“开始”。我会更新我的原始文章,以便更清楚地看到代码。 – RyanInBinary 2012-08-08 14:34:51