在 TabHost 内更改活动转换

发布于 2024-12-10 08:39:55 字数 906 浏览 5 评论 0原文

我已使用 overridePendingTransition() 成功更改了活动之间的转换。

不幸的是,当我在 TabActivity 上并使用每个选项卡内的活动时。当选项卡内容中的其中一个活动启动另一个活动时,overridePendingTransition() 似乎不起作用。

我基本上有一个 TabActivity,里面有一个带有 ListView 的活动。我正在做的是,当单击该项目时,我启动项目详细信息的活动。

这个新活动的转换动画不会被 overridePendingTransition() 覆盖,

我基本上是这样做的:

private Activity owner;
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Intent programActivity = new Intent().setClass(view.getContext(), ProgramActivity.class);
    Program program = (Program) parent.getItemAtPosition(position);
    programActivity.putExtra("programID", program.getId());
    owner.startActivity(programActivity);
    owner.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}

所以,我相信在我尝试覆盖它们之后,挂起的转换会被覆盖。

我应该在其他地方这样做吗? 我还犯了其他愚蠢的错误吗?

谢谢 !

I have successfully changed the transitions between activities using overridePendingTransition().

Unfortunately when I am on a TabActivity and use activities inside each tab. When one of those activities inside the content of the tab, starts another activity, the overridePendingTransition() seems to not work.

I basically have a TabActivity, inside it resides an activity with a ListView. What I'm doing is when the item is clicked, I launch the item details' activity.

This new activity's transition animation is not being overridden with the overridePendingTransition()

I basically do this:

private Activity owner;
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Intent programActivity = new Intent().setClass(view.getContext(), ProgramActivity.class);
    Program program = (Program) parent.getItemAtPosition(position);
    programActivity.putExtra("programID", program.getId());
    owner.startActivity(programActivity);
    owner.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}

So, I believe that the pending transition is overridden after I'm trying to override them.

Is there a different place I should do that?
Am I doing some other stupid mistake?

Thanks !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空名 2024-12-17 08:39:55

我在从片段中调用 overridePendingTransition() 时遇到了类似的问题,因为片段没有定义 overridePendingTransition() 方法。

我用以下方法解决了这个问题:

getActivity().overridePendingTransition(R.anim.enterAnim, R.anim.exitAnim);

希望有帮助。该片段位于 TabHost 内。

I had a similar problem with calling overridePendingTransition() from within a Fragment, because Fragments do not have overridePendingTransition() method defined.

I solved it using:

getActivity().overridePendingTransition(R.anim.enterAnim, R.anim.exitAnim);

Hope it helps. The Fragment was within a TabHost.

写下不归期 2024-12-17 08:39:55

我发现问题是因为我的视图是选项卡内的子活动。

为了正确重写转换,我重写了 TabActivity 上的 onPause 方法,现在它可以按预期工作。

注意:如果您的 Activity 不在选项卡内,您仍然必须在项目的侦听器上使用 overridePendingTransition()

I found out that the problem was because my view was a sub-activity inside a tab.

To correctly override the transitions I've overridden the onPause method on the TabActivity and it now works as expected.

Note: You still have to use the overridePendingTransition() on the listener for your items if your activity is NOT within a tab.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文