2017-06-05 55 views
0

我想开发一个Android应用程序,它有一个ActionBarDrawerToggle汉堡包图标。一切正常,但汉堡包图标显示不正确。从图像中可以看到它从顶部剪下。我试图调整工具栏的高度,但没有用。请问我的布局文件有问题,请注意。下面是我的主要活动文件和图像文件汉堡切换图标显示不正确。

<android.support.v4.widget.DrawerLayout 
 

 
    xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
 
    android:id="@+id/drawerLayout" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    tools:openDrawer="start" 
 
    tools:context="com.example.xxx.zzz.MainActivity"> 
 

 

 
    <!--<LinearLayout 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:orientation="vertical"> 
 

 

 
    </LinearLayout>--> 
 
    <android.support.design.widget.NavigationView 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:id="@+id/navView" 
 
     app:menu="@menu/drawer_menu" 
 
     app:headerLayout="@layout/header_layout" 
 
     android:layout_gravity="start" 
 
     > 
 

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

 

 
<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:id="@+id/main_content" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    android:background="@android:color/white" 
 
    android:fitsSystemWindows="true" 
 
    > 
 

 

 
    <android.support.v7.widget.Toolbar 
 
     android:id="@+id/mtoolbar" 
 
     xmlns:android="http://schemas.android.com/apk/res/android" 
 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
 
     android:layout_width="match_parent" 
 
     android:background="@color/colorPrimary" 
 
     android:layout_height="60dp" 
 
     app:layout_collapseMode="pin" 
 
     android:elevation="5dp" 
 
     android:minHeight="?attr/actionBarSize" 
 
     app:theme="?actionBarTheme" 
 
     /> 
 

 
    <!-- android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" --> 
 
    <android.support.design.widget.AppBarLayout 
 
     android:id="@+id/appbar" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="@dimen/detail_backdrop_height" 
 
     android:background="?attr/colorPrimary" 
 
     android:fitsSystemWindows="true" 
 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
 
     > 
 

 

 
     <android.support.design.widget.CollapsingToolbarLayout 
 
      android:id="@+id/collapsing_toolbar" 
 
      android:layout_width="match_parent" 
 
      android:layout_height="match_parent" 
 
      android:fitsSystemWindows="true" 
 
      app:contentScrim="?attr/colorPrimary" 
 
      app:titleEnabled="false" 
 
      app:expandedTitleTextAppearance="@android:color/transparent" 
 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 
 

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

 

 

 
       <ImageView 
 
        android:id="@+id/backdrop" 
 
        android:layout_width="match_parent" 
 
        android:layout_height="wrap_content" 
 
        android:scaleType="centerCrop" 
 
        android:src="@drawable/tea2" 
 
        app:layout_collapseMode="parallax" 
 
        app:layout_collapseParallaxMultiplier="0.7" 
 
        /> 
 

 
       <LinearLayout 
 
        android:layout_width="wrap_content" 
 
        android:layout_height="wrap_content" 
 
        android:layout_centerInParent="true" 
 
        android:gravity="center_horizontal" 
 
        android:orientation="vertical"> 
 

 
        <TextView 
 
         android:id="@+id/text_view_products" 
 
         android:layout_width="wrap_content" 
 
         android:layout_height="wrap_content" 
 
         android:text="Our Products" 
 
         android:textColor="@android:color/black" 
 
         android:textSize="@dimen/backdrop_title" /> 
 

 
        <TextView 
 
         android:layout_width="wrap_content" 
 
         android:layout_height="wrap_content" 
 
         android:text="Buy online!" 
 
         android:textStyle="italic" 
 
         android:textColor="@android:color/black" 
 
         android:textSize="@dimen/backdrop_subtitle" /> 
 

 
       </LinearLayout> 
 
      </RelativeLayout> 
 

 

 

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

 

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

 

 

 
    <include layout="@layout/card_view" /> 
 

 

 

 

 

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

 

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

enter image description here

+0

http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/本教程 –

回答

0

有我的一个小错误。我需要将导航视图部分放在协调器布局部分之后。在这样做,它工作正常。修改后的代码如下:

<?xml version="1.0" encoding="utf-8"?> 
 
<android.support.v4.widget.DrawerLayout 
 

 
    xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
 
    android:id="@+id/drawerLayout" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    tools:openDrawer="start" 
 
    tools:context="com.example.himangshugogoi.bcd.MainActivity"> 
 

 

 
    <!--<LinearLayout 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:orientation="vertical"> 
 

 

 
    </LinearLayout>--> 
 

 
<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:id="@+id/main_content" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    android:background="@android:color/white" 
 
    android:fitsSystemWindows="true" 
 
    > 
 

 
    <android.support.v7.widget.Toolbar 
 
     android:id="@+id/mtoolbar" 
 
     xmlns:android="http://schemas.android.com/apk/res/android" 
 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
 
     android:layout_width="match_parent" 
 
     android:background="@color/colorPrimary" 
 
     android:layout_height="60dp" 
 
     app:layout_collapseMode="pin" 
 
     android:elevation="5dp" 
 
     android:minHeight="?attr/actionBarSize" 
 
     app:popupTheme="@layout/toolbar_layout" 
 
     app:theme="?actionBarTheme" 
 
     /> 
 

 

 
    <!-- android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" --> 
 
    <android.support.design.widget.AppBarLayout 
 
     android:id="@+id/appbar" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="@dimen/detail_backdrop_height" 
 
     android:background="?attr/colorPrimary" 
 
     android:fitsSystemWindows="true" 
 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
 
     > 
 

 

 

 

 
     <android.support.design.widget.CollapsingToolbarLayout 
 
      android:id="@+id/collapsing_toolbar" 
 
      android:layout_width="match_parent" 
 
      android:layout_height="match_parent" 
 
      android:fitsSystemWindows="true" 
 
      app:contentScrim="?attr/colorPrimary" 
 
      app:titleEnabled="false" 
 
      app:expandedTitleTextAppearance="@android:color/transparent" 
 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 
 

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

 

 

 
       <ImageView 
 
        android:id="@+id/backdrop" 
 
        android:layout_width="match_parent" 
 
        android:layout_height="wrap_content" 
 
        android:scaleType="centerCrop" 
 
        android:src="@drawable/tea2" 
 
        app:layout_collapseMode="parallax" 
 
        app:layout_collapseParallaxMultiplier="0.7" 
 
        /> 
 

 
       <LinearLayout 
 
        android:layout_width="wrap_content" 
 
        android:layout_height="wrap_content" 
 
        android:layout_centerInParent="true" 
 
        android:gravity="center_horizontal" 
 
        android:orientation="vertical"> 
 

 
        <TextView 
 
         android:id="@+id/text_view_products" 
 
         android:layout_width="wrap_content" 
 
         android:layout_height="wrap_content" 
 
         android:text="Our Products" 
 
         android:textColor="@android:color/black" 
 
         android:textSize="@dimen/backdrop_title" /> 
 

 
        <TextView 
 
         android:layout_width="wrap_content" 
 
         android:layout_height="wrap_content" 
 
         android:text="Buy online!" 
 
         android:textStyle="italic" 
 
         android:textColor="@android:color/black" 
 
         android:textSize="@dimen/backdrop_subtitle" /> 
 

 
       </LinearLayout> 
 
      </RelativeLayout> 
 

 

 

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

 

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

 

 

 
    <include layout="@layout/card_view" /> 
 

 

 

 

 

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

 
    <android.support.design.widget.NavigationView 
 
     android:layout_width="match_parent" 
 
     android:layout_height="match_parent" 
 
     android:id="@+id/navView" 
 
     app:menu="@menu/drawer_menu" 
 
     app:headerLayout="@layout/header_layout" 
 
     android:layout_gravity="start" 
 
     /> 
 

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