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