android:使用ActivityGroup嵌入活动

发布于 2024-09-10 15:34:17 字数 268 浏览 0 评论 0原文

我正处于构建应用程序的概念化/设计阶段,但遇到了一些障碍。本质上,我正在寻找一种将一个活动嵌入到另一个活动的 UI 中的方法,类似于 TabHost/TabActivity 的方式。屏幕顶部将有一个窗口,其中包含其他活动,其下方将是独立于上述活动的按钮和控件,并且应始终可见。用户将能够从窗口中的一个活动导航到另一个活动,而不会对以下控件造成任何更改。

在研究这个问题时,我遇到了 ActivityGroup,它看起来很有用,但是我将如何实现它呢?有人有 ActivityGroup 的经验或有其他想法吗?

Im in the conceptualizing/design phase of building an app and i've hit a bit of a snag. Essentially i was looking for a way to embed one activity into the UI of another similar to how a TabHost/TabActivity. There would be a window at the top of the screen which would contain the other activity, and below that would be buttons and controls that are independent of the above activity and should always be visible. The user would be able to navigate from one activity to another in the window without causing any change to the below controls.

While looking into the issue i ran across ActivityGroup, which looked like it would be useful, but how would i implement it? Anyone have experience with ActivityGroup or have another idea?

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

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

发布评论

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

评论(1

窝囊感情。 2024-09-17 15:34:17

是的,您将实现一个 ActivityGroup,它将成为其他 Activity 的容器。当用户单击其中一个按钮时,您将获得对 LocalActivityManager 的引用,并使用它来启动和嵌入内部活动。像这样的事情:

LocalActivityManager mgr = getLocalActivityManager();

Intent i = new Intent(this, SomeActivity.class);

Window w = mgr.startActivity("unique_per_activity_string", i);
View wd = w != null ? w.getDecorView() : null;

if(wd != null) {
    mSomeContainer.addView(wd);
}

注意,使用这种方法可能非常复杂,因为除非焦点恰到好处,否则按下硬件按钮(如菜单按钮)只会触发 ActivityGroup 上的事件,而不会触发内部 Activity 的事件。将内部活动添加到容器视图后,您必须找到某种方法来聚焦内部活动,此时事件将在内部活动中发生并传播到容器活动。

这是可以做到的,我已经做到了……而且有效。只是比我想象的要复杂一点。

无论如何,我通过查看 TabHost 代码获得了大部分信息,可以找到 此处

Yes, you'd implement an ActivityGroup, which will be the container of your other Activities. When the user clicks one of the buttons, you'd get a reference to the LocalActivityManager, and use it to start, and embed the inner activity. Something like this:

LocalActivityManager mgr = getLocalActivityManager();

Intent i = new Intent(this, SomeActivity.class);

Window w = mgr.startActivity("unique_per_activity_string", i);
View wd = w != null ? w.getDecorView() : null;

if(wd != null) {
    mSomeContainer.addView(wd);
}

Note, using this method can be pretty complicated, because unless the focus is just right, pressing the hardware buttons (like the menu button) will only only trigger events on the ActivityGroup instead of the inner Activity. You have to find some way to focus the inner activity after you add it to the container view, at which point the even will happen in the inner activity and propagate to the container activity.

It can be done, I've done it... and it works. It's just a bit more complicated than I think it should be.

Anyway, I got most of this information by looking at the TabHost code, which can be found here

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