2017-05-09 59 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">