导航布局接管主要活动布局

时间:2015-07-09 08:50:20

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

我试图在我的应用中实现导航抽屉,但出于某种原因,每当我在main_activity xml布局中添加导航抽屉片段时,它都会掩盖/替换我的主要活动的内容。当我删除片段时,我的recyclerview再次正确显示。

activity_main.xml中

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

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

    <include android:id="@+id/toolbar_actionbar"
        layout="@layout/toolbar_default"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <FrameLayout android:id="@+id/container"
        android:layout_width="match_parent"
        android:clickable="true" android:layout_height="match_parent"
        android:layout_below="@id/toolbar_actionbar">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/cardList"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </FrameLayout>

</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageButton
        android:id="@+id/fab_image_button"
        android:layout_width="@dimen/fab_button_diameter"
        android:layout_height="@dimen/fab_button_diameter"
        android:background="@drawable/btn_order_hub"
        android:src="@drawable/btn_order_hub_trans"
        android:layout_above="@+id/space2"
        android:layout_alignStart="@+id/space2"
        android:tint="@android:color/white"
        android:elevation="@dimen/elevation_high"
        android:stateListAnimator="@anim/button_elevation"/>

    <Space
        android:layout_width="@dimen/fab_button_diameter"
        android:layout_height="@dimen/fab_button_margin_bottom"
        android:layout_alignParentBottom="true"
        android:layout_toStartOf="@+id/space"
        android:id="@+id/space2" />

    <Space
        android:layout_width="@dimen/fab_button_margin_right"
        android:layout_height="@dimen/fab_button_diameter"
        android:layout_gravity="left|top"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:id="@+id/space" />
</RelativeLayout>

<fragment android:id="@+id/navigation_drawer"
    android:layout_width="@dimen/navigation_drawer_width" android:layout_height="match_parent"
    android:layout_gravity="start"
    android:name="com.android.expresso.expresso.NavigationDrawerFragment"
    tools:layout="@layout/fragment_navigation_drawer" />
<!-- android:layout_marginTop="?android:attr/actionBarSize"-->

fragment_navigation_drawer.xml

<ListView 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:choiceMode="singleChoice"
   android:divider="@android:color/transparent" android:dividerHeight="0dp"
   android:background="#cccc"
   tools:context="com.android.expresso.expresso.NavigationDrawerFragment" />

这就是我运行应用程序时会发生的事情。 注意:Matthew SteinhardtMatthew.steinhardt@gmail.com是应该仅在导航抽屉打开时显示的文字,但出于某种原因,它也会显示在我的主要活动。

- 问题图片, 正确 ,导航抽屉的图片:

enter image description here enter image description here

如果您需要更多信息,请知道,谢谢!

1 个答案:

答案 0 :(得分:1)

<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
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

   <ListView xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"    
   android:layout_width="240dp"
   android:layout_height="match_parent" android:choiceMode="singleChoice"
   android:divider="@android:color/transparent" android:dividerHeight="0dp"
   android:background="#cccc"
   tools:context="com.android.expresso.expresso.NavigationDrawerFragment" />
</android.support.v4.widget.DrawerLayout>

希望这会帮助你。

相关问题