折叠工具栏布局中的工具栏未固定

时间:2016-06-19 20:15:31

标签: android layout android-design-library

编辑:更新了平板电脑gfycat链接。

我的手机布局有问题。即使我在工具栏上设置了app:layout_collapseMode =“pin”,它也会在屏幕上滚动,此外,经典的“幻灯片”动作也会被禁用。

手机布局: https://gfycat.com/EnviousPaleFlicker

平板电脑布局: https://gfycat.com/QueasyPowerlessGrayfox

这是布局被细节活动和细节片段膨胀。

movie_detail.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:fitsSystemWindows="true"
    tools:context="com.example.bunny.popularmoviesapp.MovieDetailActivity">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:fitsSystemWindows="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways">

            <!--alpha here to help make text readable over image-->
            <ImageView
                android:id="@+id/backdrop_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="centerCrop"
                android:alpha="0.6"
                app:layout_collapseMode="parallax"
                android:adjustViewBounds="true"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/detail_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
        </android.support.design.widget.CollapsingToolbarLayout>

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:id="@+id/movie_detail"
                style="?android:attr/textAppearanceLarge"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:padding="16dp"
                android:textIsSelectable="true"
                tools:context="com.example.bunny.popularmoviesapp.MovieDetailFragment" />

            <TextView
                android:id="@+id/overview_text"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="@dimen/text_margin"
                android:layout_below="@id/movie_detail" />
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

1 个答案:

答案 0 :(得分:5)

用这些替换你的AppBarLayout和CollapsingToolbarLayout开场标签,

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/app_bar_height"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

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