2017-07-17 19 views
0

在我的Android应用程序,我有一个活动与导航抽屉。我也在其中使用CollapsingToolbarLayout与ImageView,因为它也想要和图像作为工具栏的背景,在滚动后会崩溃。 现在,图像显示并很好地显示,但工具栏不显示。我看不到按钮来打开导航抽屉或菜单按钮。这里是我的布局文件:虽然使用导航抽屉CollapsingToolbarLayout与ImageView工具栏不显示

activity_main.xml中

<android.support.v4.widget.DrawerLayout 
mlns: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/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:fitsSystemWindows="true" 
tools:openDrawer="start"> 

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

<android.support.design.widget.NavigationView 
    android:id="@+id/nav_view" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:fitsSystemWindows="true" 
    app:headerLayout="@layout/navigation_drawer_header" 
    app:menu="@menu/activity_main_drawer" 
    android:background="@color/navigation_view_background" 
    app:itemIconTint="@color/navigation_item_color" 
    app:itemTextColor="@color/navigation_item_color"/> 
</android.support.v4.widget.DrawerLayout> 

app_bar_main.xml

<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.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 
    <android.support.design.widget.CollapsingToolbarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/transparent" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:expandedTitleMarginStart="40dp" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:layout_collapseMode="pin" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 
     <include 
      android:id="@+id/activity_description_header" 
      layout="@layout/fragment_edit_header" 
      app:layout_collapseMode="parallax" 
      app:layout_collapseParallaxMultiplier="0.75" /> 
    </android.support.design.widget.CollapsingToolbarLayout> 


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

<include layout="@layout/content_main" /> 
</android.support.design.widget.CoordinatorLayout> 

fragment_edit_header.xml

<layout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto"> 

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical">   

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="200dp" 
     android:scaleType="centerCrop" 
     android:src = "@drawable/image"/> 

</FrameLayout> 
</layout> 

回答

1

试试这个

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:ads="http://schemas.android.com/apk/res-auto" 
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" 
tools:context="com.ncrypted.redfox.Activities.HomeClass"> 

<android.support.design.widget.AppBarLayout 
    android:id="@+id/app_bar_layout_home" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fitsSystemWindows="true" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsingToolBar_hotel_home" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     app:contentScrim="?attr/colorPrimary" 
     app:expandedTitleMarginEnd="64dp" 
     app:expandedTitleMarginStart="48dp" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

     <ImageView 
      android:id="@+id/img_hotel_home" 
      android:layout_width="match_parent" 
      android:layout_height="300dp" 
      android:fitsSystemWindows="true" 
      android:scaleType="centerCrop" 
      android:src="@drawable/redfox" 
      app:layout_collapseMode="parallax" /> 

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

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

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


    <android.support.v4.widget.NestedScrollView 
     android:id="@+id/scrollNestedData" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"   app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     // add here your other controls 


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

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

使用这个主题

<style name="AppTheme.ActionBar.Transparent" parent="AppTheme"> 
    <item name="windowActionBarOverlay">true</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="colorPrimary">@android:color/transparent</item> 
    <item name="colorPrimaryDark">@android:color/transparent</item> 
    <item name="windowActionBar">false</item> 
    <item name="windowNoTitle">true</item> 

    <!-- <item name="android:homeAsUpIndicator">@mipmap/ic_left_back</item>--> 
</style> 

问我任何查询

+0

使用布局的情况下,我现在可以看到工具栏,但ImageView的是它的下面而不是在后台 – matip

+0

@matip你可以提供图像哪种类型的布局,你想 –

+0

我想这样的事情。向下滚动后,工具栏背景中的图像。 http://antonioleiva.com/wp-content/uploads/2015/07/collapsing-toolbar-layout.gif – matip