[英]Fragment - Wait until transaction animation is complete
I am using a simple slide left, slide right custom animation when I perform FragmentTransaction. 我正在使用一个简单的幻灯片,当我执行FragmentTransaction时向右滑动自定义动画。 My problem is, the fragment I'm loading with the transaction animation contains code in the onResume() to make a HTTP call which causes my "Please Wait" progress dialog to show.
我的问题是,我用事务动画加载的片段包含onResume()中的代码,以进行HTTP调用,这会导致我的“Please Wait”进度对话框显示。 It works, but I would like the move my code from onResume to another method in the Fragment that would not fire until the fragment is completely loaded.
它可以工作,但是我希望将我的代码从onResume移动到Fragment中的另一个方法,在片段完全加载之前不会触发。 In other words, when the animation is complete and it is completely slid into place.
换句话说,当动画完成并且它完全滑入到位时。
I use this to start the new fragment 我用它来启动新片段
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction ft = manager.beginTransaction();
ft.setCustomAnimation(R.anim.slide_in_right, R.anim.slide_out_left);
ft.replace(R.id.realtabcontent, new MyFragment());
ft.commit();
and I want the method in MyNewFragment() to initialize after the animation is 100% complete 并且我希望MyNewFragment()中的方法在动画完成100%后初始化
Is that possible? 那可能吗?
There are two approaches possible here, 这里有两种方法,
Implement an AnimationListener on the slide-in animation. 在幻灯片动画中实现AnimationListener。
animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } });
In onAnimationEnd() of the listener, call a method in the fragment to make the HTTP call. 在侦听器的onAnimationEnd()中,调用片段中的方法来进行HTTP调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.