嵌套滚动视图位于支持设计中折叠工具栏的后面

时间:2015-12-22 05:51:11

标签: android-coordinatorlayout nestedscrollview

这里是NestedScrollView

中的CoordinatorLayout
<?xml version="1.0" encoding="utf-8"?>
<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=".fests.ActFestivalDetail">


    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_parent"
        android:layout_height="@dimen/d_192"
        android:layout_width="match_parent"
        android:fitsSystemWindows="true"
        android:orientation="vertical">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/app_bar_collapse"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:expandedTitleMarginBottom="@dimen/d_32"
            app:expandedTitleMarginEnd="@dimen/d_64"
            app:expandedTitleMarginStart="@dimen/d_48"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            >
            <ImageView
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="center"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"/>
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_height="@dimen/d_192"
                android:layout_width="match_parent"
                android:fitsSystemWindows="true"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_collapseMode="pin"/>

        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.NestedScrollView
        android:id="@+id/nested_scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:behavior_overlapTop="@dimen/d_64"
        >
        <include layout="@layout/detail_card"/>
    </android.support.v4.widget.NestedScrollView>

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

无论何时我尝试向上滚动它都会很顺利,直到它落后于工具栏。 任何建议。?

1 个答案:

答案 0 :(得分:0)

我认为你错过了一些基本的Android XML技术。

简单回答是线性布局

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

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_parent"
        android:layout_width="match_parent"
        android:layout_height="@dimen/d_192"
        android:fitsSystemWindows="true"
        android:orientation="vertical">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/app_bar_collapse"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:expandedTitleMarginBottom="@dimen/d_32"
            app:expandedTitleMarginEnd="@dimen/d_64"
            app:expandedTitleMarginStart="@dimen/d_48"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/header"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="center"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="@dimen/d_192"
                android:fitsSystemWindows="true"
                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:id="@+id/nested_scroll"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:behavior_overlapTop="@dimen/d_64"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <include layout="@layout/detail_card" />
    </android.support.v4.widget.NestedScrollView>
</LinearLayout>

这可能有效。