如何将一项活动实施到另一项活动中?

发布于 2024-12-20 19:43:17 字数 388 浏览 2 评论 0原文

我不知道这是否是一个愚蠢的问题,因为它是我的第一个应用程序之一..但如果是这样,请也解释一下原因!

如果我创建一个基于选项卡的活动结构,我几乎得到了我想要的东西,但仅限于选项卡。我想要的通常是在包含主界面的一个主活动中打开第二个甚至第三个活动。

示例:在整个应用程序运行时,出于某种原因,我在左下角有一个标题栏和一个小图标。现在:我如何通过主要活动来控制它们,并同时在现有界面中打开一些其他活动/视图?然后它应该显示在标题栏下方并位于小图标下方(该图标并不重要,只是虚构的)。另外,如果我可以为这些嵌入的活动/视图添加一些淡入淡出效果,那就太好了。这有可能吗?

我目前只知道如何打开活动来填充整个屏幕,除了选项卡的情况...也许我只是没有足够地检查选项卡结构..但是,我会对每个答案感到高兴!

问候

I don't know if it's a dumb question because it is one of my first apps.. but if that's the case, please also explain why!

If I create a Tab-Based Activity-Structure, I get nearly what I am asking for but only for Tabs. What I want is generally opening a second or even third activity in one main-activity which contains the main-interface.

Example: I have a Title-Bar and a little icon at the bottom-left corner for some reason during the whole app runtime. Now: How can I control them with the main activity and open at the same time some other activities/views into the existing interface? It should then be shown below the title bar and lying underneath the little icon (the icon is not really important, just fictional). Also it would be nice if I could add some fade in effects to these embedded activities/views. Is that somehow possible?

I currently only know, how to open activities each over another filling the whole screen, except in the case of tabs... maybe I only haven't inspected the tab structure enough.. however, I would be delighted about each answer!

Regards

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

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

发布评论

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

评论(1

桜花祭 2024-12-27 19:43:17

您正在寻找的是 Fragments。

Fragment 可用于填充屏幕的一部分,同时在完全不同的屏幕中执行其他操作。
在您的示例中,您可以创建一个包含两个 Fragments 的主活动。一个 Fragment 控制标题栏,另一个控制主要内容区域。
通过按一下按钮将内容区域中当前的 Fragment 替换为不同的 Fragment,您就可以实现您正在寻找的行为。至少,我在包含主要内容区域和音乐播放器的应用程序中就是这样做的。当主要内容发生变化时,音乐播放器保持不变。

遗憾的是,我现在无法提供任何示例代码,但这里有一个教程可以帮助您入门:

What you are looking for, are Fragments.

Fragments can be used to fill a part of the screen, while doing something else entirely in a different one.
In your example you can create a main activity that contains two Fragments. One Fragment controls the title bar, the other one controls the main content area.
By replacing the current Fragment in your content area with a different one on the press of a button, you can achieve the behavior you are looking for. At least, that's how I did it in an app of mine containing a main content area and a music player. The music player stays in place while the main content changes.

Sadly I can't provide any example code right now, but here is a tutorialthat should help you get started:

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