如何在同一个框架或布局中使用片段并一一显示它们?
这是我的平板电脑应用程序的屏幕截图(暂时不使用片段):
如您所见,左侧有一个小菜单,其中包含我的每一项活动的图标。
目前,这些图标启动了新的活动,但我希望它们在右侧的框架中启动fragmentactivity,因此所有内容都将在同一个面板中。
但是仔细阅读有关片段的帖子和文档后,我只能看到片段同时显示:
从这里: http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment class="com.example.android.apis.app.TitlesFragment"
android:id="@+id/titles" android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent" />
<FrameLayout android:id="@+id/details" android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent" />
</LinearLayout>
所以,为了在同一个地方显示不同的片段,我该怎么办? 我想在 View=gone 上玩是我能想到的最糟糕的主意,不是吗?
非常感谢您的帮助。
Here is a screenshot of my tablet application (not using fragments for now):
So as you can see, there is a little menu on the left with icon for each one of my activities.
Currently, these icons launches new activities, but I would like them to launch fragmentactivity in the frame on the right, so everything would be in the same pannel.
But after reading carefully posts and docs about fragments, I can only see that fragments are displayed at the same time:
from here: http://android-developers.blogspot.com/2011/02/android-30-fragments-api.html
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment class="com.example.android.apis.app.TitlesFragment"
android:id="@+id/titles" android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent" />
<FrameLayout android:id="@+id/details" android:layout_weight="1"
android:layout_width="0px"
android:layout_height="match_parent" />
</LinearLayout>
So, in order to display different fragments in the same place, what should I do?
I guess that playing on View=gone is the worst idea I can have, isn't it?
Thank a lot for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你必须将你的活动迁移到碎片中。例如,您将拥有一个
RoutePlanner
片段、一个TrafficIssues
片段等。按下其中一个图标时,您将使用FragmentManager 将详细信息
FrameLayout
替换为相应的片段。You have to migrate your activities to fragments. You will then have, for example, a
RoutePlanner
fragment, aTrafficIssues
fragment, etc. When one of the icons is pressed, you will use theFragmentManager
to replace the detailsFrameLayout
with the corresponding fragment.