0

我正在尝试CollapsingToolbarLayout使用NestedScrollView,但它没有NestedScrollView正确地跟随滚动。NestedScrollView当到达顶端或底端时它会移动一点,但这显然不是预期的行为。

哦,contentScrim封面ImageView也是。

这是发生了什么的视频:https ://youtu.be/1GlTJq5fd0U

这是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="256dp"
        android:fitsSystemWindows="true">

        <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="64dp"
            app:expandedTitleMarginStart="48dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:toolbarId="@+id/article_app_bar">

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

            <include
                android:id="@+id/article_app_bar"
                layout="@layout/article_app_bar" />
        </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"
        android:layout_gravity="fill_vertical"
        android:fitsSystemWindows="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:layout_scrollFlags="scroll|enterAlways">

        <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>
4

1 回答 1

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>
于 2015-08-19T13:03:26.180 回答