2016-06-11 54 views
0

我用NavigationView制作了一个Activity。当我选择一个NavigationView项时,它会加载一个片段。 这是包含了我的活动和片段布局将.xml:在ActionBar后面的ListViews

<?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" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true"> 

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

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

     //Layout for activity 
     <RelativeLayout 
      android:id="@+id/Separator" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      > 

      <ListView 
       android:id="@+id/FirstList" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:choiceMode="multipleChoice" 
       android:clickable="false" /> 


     </RelativeLayout> 

     //Layout for fragment 
     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 

      <ListView 
       android:id="@+id/SecondList" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" /> 
     </RelativeLayout> 
    </LinearLayout> 

    <include 
     layout="@layout/app_bar_main" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 

</RelativeLayout> 

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    app:headerLayout="@layout/nav_header_main" 
    app:menu="@menu/activity_main_drawer" /> 

</android.support.v4.widget.DrawerLayout> 

的问题是列表(列表视图)。他们在行动栏后面,我不知道为什么。 enter image description here

我认为问题是与.xml。但如果有必要,我提供更多的代码。谢谢。

编辑app_bar.xml:

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

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

</android.support.design.widget.AppBarLayout> 



</android.support.design.widget.CoordinatorLayout> 
+0

您使用的活动相同的XML,如果没有,请在你的问题中分离片段如下变化 – KDeogharkar

+0

是的,我使用相同的.xml。 – tomss

+0

我可以看到你的'app_bar_main.xml'吗? –

回答

0

这是因为错误的XML的发生。

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

    <LinearLayout 

添加ID此布局。

 android:id="@+id/list_layout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 

添加,然后终于使app_bar_main

<include 
    layout="@layout/app_bar_main" 
    android:layout_above="@id/list_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" /> 
+0

我已对您的答案进行了更改。现在ActionBar已经消失了。我认为是在屏幕之外。 – tomss