【问题标题】:Navigation Layout Takes over Main Activity Layout导航布局接管主要活动布局
【发布时间】:2015-07-09 08:50:20
【问题描述】:

我正在尝试在我的应用程序中实现一个导航抽屉,但由于某种原因,每当我在 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 是应该只在导航抽屉打开时显示的文本,但由于某种原因,它也显示在我的主要活动中。

- 问题图像,,导航抽屉图像:

如果您需要更多信息,请告诉我,谢谢!

【问题讨论】:

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


    【解决方案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>
    

    希望对您有所帮助。

    【讨论】:

    • 似乎没有帮助:(
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-19
    • 2016-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-06
    相关资源
    最近更新 更多