【问题标题】:How to show fragment on performing certain action [duplicate]如何在执行某些操作时显示片段[重复]
【发布时间】:2017-09-11 12:53:20
【问题描述】:

实际上我正在开发一个带有导航抽屉的应用程序,我想使用片段而不是单独的活动。 我想怎么做? 提前致谢。

【问题讨论】:

  • 在你的navigationdrawer活动中添加一个框架布局并制作片段,然后使用片段管理器来显示它......
  • @SushilDubey 实际上我创建了一个片段和它的布局文件,我将它包含在我的主要活动的布局文件中,并创建了片段管理器,片段事务开始..等等但是片段中的内容正在显示直接与任何操作无关。
  • 仅在执行操作后添加片段
  • @AyushKhare 是的,我也做过同样的事情,当用户在导航抽屉中选择一个选项时,应该调用这个片段。

标签: java android android-fragments fragmenttransaction


【解决方案1】:

检查此示例代码。希望这对您有所帮助。

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include layout="@layout/toolbar_layout">
        <!--The Toolbar Layout if you have toolbar-->
    </include>

    <FrameLayout
        android:id="@+id/base_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <!--The layout where you need to add different
            fragments on click of nabigation items-->

    </FrameLayout>

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:orientation="vertical">

 <!--The navigation drawer items-->
</LinearLayout>

【讨论】:

    猜你喜欢
    • 2012-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-10
    • 2013-01-17
    相关资源
    最近更新 更多