在先前的 Activity 之上显示新的 Activity,但仅部分覆盖先前的 Activity
我有一个活动 A,它有一个“向下”按钮(参见上图)。当我按下此按钮时,我想在 Activity A 之上启动 Activity B,以便底部的 Activity A 的一些内容仍然可见。 Activity B 可以依次启动许多其他 Activity(C、D 等),以便它们仅显示在与 B 相同的屏幕区域内。有谁知道这是否可能,如果可以,我该怎么做?
编辑
我知道我可以将 android:theme="@android:style/Theme.Dialog"
添加到我的 Activity 的清单声明中。但是,据我所知,它显示在屏幕中央,并且无法根据需要调整其大小。如果我错了请指正
I have an Activity A which has a "down" button (see image above). When I press this button, I want to launch an Activity B on top of Activity A such that some of Activity A at the bottom is still visible. Activity B can in turn launch a number of other Activities (C, D etc) such that they only display within the same screen area as B. Does anybody know whether this is possible and, if so, how I can go about it?
Edit
I am aware that I can add android:theme="@android:style/Theme.Dialog"
to my Activity's manifest declaration. However, as far as I am aware, this displays in the centre of the screen and not such that I can resize it how I require. Correct me if I am wrong ????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是应该位于活动 A 之上的活动的 XML:
现在,在活动 B、C 等的 manifest 中:
在 values/styles.xml 中:
最后,在drawable/theme_transparent.xml中:
This is the XML for activities that should be on top of Activity A:
Now, in your manifest for Activities B, C etc:
In values/styles.xml:
Finally, in drawable/theme_transparent.xml:
你需要使用的是 Fragments。
Fragments 可以用来填充屏幕的一部分,同时在完全不同的屏幕中执行其他操作。
在您的示例中,您可以创建一个包含两个
Fragments
的主活动。一个Fragment
控制“A 活动”,另一个控制“B 活动”等等。通过按下按钮将“B 活动”区域中的当前
Fragment
替换为不同的 Fragment,您就可以实现您正在寻找的行为。至少,我在包含主要内容区域和音乐播放器的应用程序中就是这样做的。当主要内容发生变化时,音乐播放器保持不变。遗憾的是,我现在无法提供任何示例代码,但这里有一个教程可以帮助您入门:
如果您使用的是 3.0 以下的 Android 版本,则可以使用兼容性包。
http://developer.android.com/sdk/compatibility-library.html
http://mobile.tutsplus.com/tutorials/android/android-compatibility-working-with-fragments/
What you need to use, 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
. OneFragment
controls the "A activity" , the other one controls the "B activity" and the other ones..By replacing the current
Fragment
in your "B activity" 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:
In case you are working with an Android version below 3.0, you can use the Compatibility package.
http://developer.android.com/sdk/compatibility-library.html
http://mobile.tutsplus.com/tutorials/android/android-compatibility-working-with-fragments/
关于“编辑”,实际上,您可以移动/调整对话框主题活动的大小。
例如,要使您的 Dialog 主题活动显示在屏幕顶部而不是默认的中心,并且占屏幕宽度的 80%,只需在 Dialog 主题活动中的
setContentView
之后添加以下内容:Regarding your "Edit", actually, you can move around / resize a Dialog themed activity.
For example, to make your Dialog themed activity appear at the top of the screen instead of the default center and be 80% width of the screen, just add the following after
setContentView
in your Dialog themed activity: