CollapsingToolbarLayout& NestedScrollView不能一起工作

时间:2015-08-18 13:35:49

标签: android android-design-library androiddesignsupport android-collapsingtoolbarlayout android-support-design

我尝试fadeIn-fadeOutCollapsingToolbarLayout合作,但它并没有正确跟随NestedScrollView的滚动。当NestedScrollView到达顶端或底端时它会移动一点,但这显然不是预期的行为。

哦,NestedScrollView也会立即覆盖contentScrim

以下是视频:https://youtu.be/1GlTJq5fd0U

这里是xml:

ImageView

1 个答案:

答案 0 :(得分:2)

我最后玩了一堆xml标签,并且不知道哪一个修复了问题,但这里是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:id="@+id/articleLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.gmail.senokt16.bosphoruschronicle.ArticleActivity">


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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/articleCollapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/primaryColor"
            app:expandedTitleMarginEnd="96dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <View
                android:layout_width="match_parent"
                android:fitsSystemWindows="true"
                android:layout_height="match_parent"
                android:background="@drawable/gradient"
                />
            <ImageView
                android:id="@+id/articleActivityImage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:layout_collapseMode="parallax"
                android:scaleType="centerCrop"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/article_app_bar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"/>
        </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:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingTop="24dp">

            <TextView
                android:id="@+id/articleActivityContents"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:paddingBottom="30dp"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:paddingTop="5dp" />
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/articleFAB"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@android:drawable/ic_menu_share"
        app:layout_anchor="@id/articleAppBarLayout"
        app:layout_anchorGravity="bottom|right|end" />


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