如何添加两个片段一起在一个的FrameLayout在运行时 [英] How to add two fragments together in a frameLayout in runtime

查看:163
本文介绍了如何添加两个片段一起在一个的FrameLayout在运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个11014633与抽屉式导航和我有内容查看的布局是这样的:

I am developing an andorid application with navigation drawer and I have a layout for contentview like this:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:dividerHeight="0dp"
        android:divider="@android:color/transparent"
        android:background="@color/default_color"/>
</android.support.v4.widget.DrawerLayout>

所以,我可以添加和替换片段的抽屉式导航项目的点击。一切都还好至今。

So I can add and replace fragment on navigation drawer item click. Everything okay till now.

但是,在一个情况下,点击导航抽屉一个项目,我需要显示两个片段,而不是一个(就像一个listFragment和细节片段)。我该怎么办呢?我应该添加两个碎片进入的FrameLayout呢?但如何?或者我应该改变的内容查看不同的 drawerLayout ?如果是的话,我该怎么办呢?

But in one case, on clicking an item on navigation drawer I need to show two fragments instead of one ( just like a listFragment and details fragment ). How can I do it? Should I add two fragments into the framelayout then? But how? or should I change the contentView with different drawerLayout ? If yes, how can I do this?

推荐答案

您可以只使用嵌套的片段。创建将动态创建的两个碎片,并将它们添加到其布局另一个片段。

You may just use nested fragments. Create another fragment that will dynamically create both your fragments and add them to its layout.

有关更多信息,请阅读本: http://developer.android。 COM /约/版本/ Android的4.2.html#NestedFragments

For more information read this: http://developer.android.com/about/versions/android-4.2.html#NestedFragments

这篇关于如何添加两个片段一起在一个的FrameLayout在运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆