java 为什么当我从 Fragment 跳转到一个新的 Activity 时 overridePendingTransition 没有生效?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12047456/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 07:23:22  来源:igfitidea点击:

Why overridePendingTransition does not take effect when I jump from Fragment to a new Activity?

javaandroidandroid-fragmentsandroid-activityandroid-animation

提问by djj0809

The first activity contains a Fragment, and there's a button inside the fragment, and when I click this button, I wish to jump to a new Activity with different animation. So I do it like this in the Fragment:

第一个活动包含一个片段,片段内有一个按钮,当我单击此按钮时,我希望跳转到具有不同动画的新活动。所以我在 Fragment 中这样做:

          mButton.setOnClickListener(new OnClickListener() {
               @Override
               public void onClick(View v) {
                     Intent intent = new Intent(getActivity(), NewActivity.class);
                     getActivity().startActivity(intent);
                     getActivity().overridePendingTransition(
                           R.anim.forward_activity_move_in,
                           R.anim.forward_activity_move_out);
               });

However the new animation does not take effect when moves to the new Activity, so I wonder maybe I do it wrong. I hope someone can help me, thx a lot:)

然而,当移动到新的 Activity 时,新的动画不会生效,所以我想我可能做错了。我希望有人可以帮助我,非常感谢:)

回答by djj0809

Thanks, I solved this problem, You can find solutions at Change activity transition when inside a TabHost

谢谢,我解决了这个问题,您可以在TabHost 中的更改活动转换中找到解决方案

Well the problem is not the case of Fragment, instead the TabActivity causes the problem.

那么问题不是 Fragment 的情况,而是 TabActivity 导致了问题。