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>
使用布局的情况下,我现在可以看到工具栏,但ImageView的是它的下面而不是在后台 – matip
@matip你可以提供图像哪种类型的布局,你想 –
我想这样的事情。向下滚动后,工具栏背景中的图像。 http://antonioleiva.com/wp-content/uploads/2015/07/collapsing-toolbar-layout.gif – matip