片段活动处理
我正在学习 Android 来移植我创建的 iOS 应用程序。我在理解如何同时在屏幕上显示多个活动活动(无论是通过 ActivityGroup 还是 FragmentActivity)时遇到一些困难。 ActivityGroup 已被弃用,但几乎似乎是最好的方法。
在深入了解更多细节之前,我可以使用一些帮助来确定正确(或最佳)的方法。
这是我想要创建的内容:
该应用程序应分为三个视觉部分: 1) 持续动态横幅的前 50dp。 2) 中间的主要内容区域,用于查看页面仪表板,其中包含允许导航到其他活动并替换自身的图标。 3) 底部 30 dp 音乐播放器栏。
本质上,我希望广告栏和播放器栏独立于主要内容区域工作。例如,当在主要内容区域中按下按钮时,我希望将主要内容区域替换为新的活动,例如曲目列表视图、网络视图、地图视图等。后退按钮将返回仪表板视图寻呼机的主要内容区域。
在某些情况下,我希望能够隐藏顶部和底部栏以使主要内容区域全屏显示,并且在某些情况下我希望全屏显示活动以在视觉上替换所有 3 个活动(例如访问邮件)作曲家意图、联系人意图等)
我已经能够将 FragmentActivity 组合在一起,将应用程序分为顶部片段、由 FragmentActivity 控制的中间视图页面和底部片段,但这似乎不是最好的方法作为碎片本身不是活动,用新活动替换视图分页器需要替换整个 FragmentActivity 本身。
就这一点而言,实现这种格式的最佳布局方法是什么(支持 2.1+)。
谢谢, James
添加了当前代码:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<fragment
android:name="com.dmi.AnywhereArtist.AdFragment"
android:layout_width="320dp"
android:layout_height="50dp"
android:id="@+id/ad_fragment" >
</fragment>
<android.support.v4.view.ViewPager
android:layout_width="fill_parent"
android:layout_height="0dp"
android:id="@+id/main_pager"
android:layout_weight="100"
android:background= "#00aa00" />
<fragment
android:name="com.dmi.AnywhereArtist.PlayerFragment"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:id="@+id/player_fragment" >
</fragment>
</LinearLayout>
I am in the process of learning Android to port over an iOS app that I created. I am having some trouble understanding how to have multiple active activities on screen at once whether it be through a ActivityGroup or FragmentActivity. ActivityGroup is deprecated but almost seems like the best approach.
I could use some help in determining the correct (or best) approach before diving into further details.
Here is what I am trying to create:
The app should be broken into three visual sections:
1) Top 50dp for a dynamic banner that persists.
2) Main Content Area in the middle for a viewpager dashboard with icons that allows navigation to other activities and replaces itself.
3) Bottom 30 dp music player bar.
Essentially, I want the Ad bar and Player bar work independent of the main content area. For example, when a button is pressed in the main content area, I would like the main content area to be replaced with a new activity such as a listview of tracks, a webview, a map view, etc. The back button would return the main content area to the dashboard view pager.
There would also be cases where I would like to be able to hide the top and bottom bars to make the main content area full screen and also cases where I would like an activity presented full screen to replace all 3 visually (such as accessing a mail composer intent, contacts intent, etc.)
I've been able to put together a FragmentActivity that separates the app into a top fragment, middle viewpager controlled by the FragmentActivity, and bottom fragment but this seems like it wouldn't be the best approach as the fragments are not activities themselves and replacing the view pager with a new activity would require replacing the entire FragmentActivity itself.
To the point, what would be the best layout approach to implement this format (with 2.1+ support).
Thanks,
James
Added Current Code:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<fragment
android:name="com.dmi.AnywhereArtist.AdFragment"
android:layout_width="320dp"
android:layout_height="50dp"
android:id="@+id/ad_fragment" >
</fragment>
<android.support.v4.view.ViewPager
android:layout_width="fill_parent"
android:layout_height="0dp"
android:id="@+id/main_pager"
android:layout_weight="100"
android:background= "#00aa00" />
<fragment
android:name="com.dmi.AnywhereArtist.PlayerFragment"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:id="@+id/player_fragment" >
</fragment>
</LinearLayout>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用碎片。
需要记住的一件重要事情是,Android 一次只允许运行一个 Activity,即使屏幕上可见多个 Activity。
片段通过允许您采用模块化应用程序组件并将它们组合起来来解决这个问题,同时仍然将所有内容保留在单个活动中。
您想要做的正是 Fragments 的设计目的。
(要获得 2.1+ 支持,请使用支持包:http://developer.android。 com/sdk/compatibility-library.html,但请记住,支持包不支持 MapFragments。)
Use Fragments.
An important thing to keep in mind is that Android only allows one Activity to run at a time, even if multiple activities are visible on screen.
Fragments work around this problem by allowing you to take modular application components and combine them, while still keeping everything inside of a single Activity.
What you're trying to do is exactly what Fragments were designed for.
(And to get 2.1+ support, use the Support Package: http://developer.android.com/sdk/compatibility-library.html. Though, keep in mind that the Support Package doesn't support MapFragments.)
,因为您不应该这样做。从一开始这就是一个糟糕的方法,现在也没有必要了。请使用碎片。
你所描述的方法似乎不错。在
ViewPager
中使用片段作为您的主要区域。使用 Android 支持包获取可追溯到 Android 1.6 的片段支持。That is because you should not do this. It was a bad approach from the beginning and is unnecessary now. Use fragments, please.
Your described approach seems fine. Use fragments in a
ViewPager
for your main area. Use the Android Support package to get fragment support going back to Android 1.6.