2017-05-09 46 views
-2

我的tabbedActivity的navigationdrawer出現問題。在選項卡式活動中導航抽屜的設計錯誤

我有一個設計問題,如果我可以這樣說。 當我打開抽屜式導航欄,我想,他是這樣開的(這是我的應用程序的另一項活動):

Good_design

但相反,它在我的標籤式的活動是這樣開的:

enter image description here

如何向下移動我的導航抽屜,以便它不會削減我的活動的標題?

我的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" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/drawerLayout" 
fitToSystemWindows="true" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true"> 

<LinearLayout 
    android:id="@+id/content" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:theme="@style/ToolBarStyle" 
     android:background="@color/colorPrimary" /> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.design.widget.TabLayout 
      android:id="@+id/tabs" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:elevation="5dp" 
      app:theme="@style/ToolBarStyle" 
      app:layout_scrollFlags="scroll|enterAlways" 
      tools:ignore="UnusedAttribute" /> 

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

    <android.support.v4.view.ViewPager 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 

    </android.support.v4.view.ViewPager> 

</LinearLayout> 

<android.support.design.widget.NavigationView 
    android:layout_width="wrap_content" 
    android:layout_height="200dp" 
    android:layout_gravity="start" 
    android:id="@+id/menu_navigation" 
    app:menu="@menu/navigation_menu"></android.support.design.widget.NavigationView> 

+0

給在XML –

+0

fitToSystemWindows =「真」爲DrawerLayout它仍然無法正常工作,你可以檢查我的更新問題的代碼嗎? – David

回答

3

您應該將工具欄移動到drawerLayout之外。 由於現在工具欄已將drawerLayout作爲其父項,所以它的顯示效果如此。

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       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.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:theme="@style/ToolBarStyle" 
    android:background="@color/colorPrimary"/> 
<android.support.v4.widget.DrawerLayout 
    android:layout_below="@+id/toolbar" 
    android:id="@+id/drawerLayout" 
    fitToSystemWindows="true" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true"> 

    <LinearLayout 
     android:id="@+id/content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 


     <android.support.design.widget.AppBarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content"> 

      <android.support.design.widget.TabLayout 
       android:id="@+id/tabs" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:elevation="5dp" 
       app:theme="@style/ToolBarStyle" 
       app:layout_scrollFlags="scroll|enterAlways" 
       tools:ignore="UnusedAttribute"/> 

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

     <android.support.v4.view.ViewPager 
      android:id="@+id/container" 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1"> 

     </android.support.v4.view.ViewPager> 

    </LinearLayout> 

    <android.support.design.widget.NavigationView 
     android:layout_width="wrap_content" 
     android:layout_height="200dp" 
     android:layout_gravity="start" 
     android:id="@+id/menu_navigation" 
     app:menu="@menu/navigation_menu"></android.support.design.widget.NavigationView> 

</android.support.v4.widget.DrawerLayout> 
</RelativeLayout> 
+0

我應該怎麼做?你能糾正我的XML文件嗎?因爲我不能移動drawerLayout的oustide,因爲我做了它。 – David

+0

更新了答案。 –

+0

謝謝!正確答案你是對的!乾杯 – David

0
<android.support.design.widget.NavigationView 
    android:layout_width="wrap_content" 
    android:layout_height="200dp" 
    android:layout_gravity="start" 
    android:layout_marginTop="@dimen/some_margin" 
    android:id="@+id/menu_navigation" 
    app:menu="@menu/navigation_menu" /> 

距頂部添加到您的NavigationView

+0

這實際上改變了一些東西,但我的菜單在中間打開 – David

+0

我剛剛添加了一個頂部邊距,無論你發佈什麼。你必須正確實施它,就是這樣。 –

0

進行此更改到您的導航視圖。

<android.support.design.widget.NavigationView 
android:layout_marginTop="?android:attr/actionBarSize" 
android:layout_width="wrap_content" 
android:layout_height="200dp" 
android:layout_gravity="start" 
android:id="@+id/menu_navigation" 
app:menu="@menu/navigation_menu">