【问题标题】:how to combine fragments layout with navigation drawer layout [closed]如何将片段布局与导航抽屉布局结合起来[关闭]
【发布时间】:2014-01-05 22:35:54
【问题描述】:

首先我是 android 新手,很抱歉不清楚点,我有 2 个布局:第一个包含片段;第二个是导航抽屉布局。

如何将两种布局整合到一个布局中?我想让主布局包含两种布局,请帮忙..

第一个布局:

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    <fragment android:name="com.example.HomeFragment"
              android:id="@+id/selectionFragment"
              android:layout_width="match_parent"
              android:layout_height="match_parent" />
    <fragment android:name="com.example.SplashFragment"
              android:id="@+id/splashFragment"
              android:layout_width="match_parent"
              android:layout_height="match_parent" />
    <fragment android:name="com.facebook.widget.UserSettingsFragment"
              android:id="@+id/userSettingsFragment"
              android:layout_width="match_parent"
              android:layout_height="match_parent" />
</LinearLayout>

第二个导航抽屉布局:

<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">

    <!-- Framelayout to display Fragments -->
    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- Listview to display slider menu -->
    <ListView
        android:id="@+id/list_slidermenu"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"        
        android:listSelector="@drawable/list_selector"
        android:background="@color/list_background"/>
</android.support.v4.widget.DrawerLayout>

【问题讨论】:

    标签: android android-layout layout android-fragments navigation-drawer


    【解决方案1】:

    您的第二个布局声明了一个FrameLayout 元素。此元素用于动态集成您的Fragment。这种做法在this page 上的官方 Android 文档中进行了说明。

    【讨论】:

    • 亲爱的 Gerard Paligot 抱歉,但我是 android 新手,我确实检查了你发送的片段链接,所以当我从链接中获得时,我可以但我的 Framlayout 中的片段?并指定哪个片段将从 MainActivity 中出现???
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-22
    • 1970-01-01
    • 2020-07-11
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    相关资源
    最近更新 更多