我在尝试使用 CoordinatorLayout 中的 NestedScrollView 进行平滑滚动时遇到了一些麻烦。现在当我滚动它停止并且没有平滑滚动时,就像我在 RecyclerView 上滚动一样。
代码:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="MissingPrefix">
<include
layout="@layout/tool_bar" />
<android.support.design.widget.CoordinatorLayout
android:layout_below="@+id/toolbar"
android:layout_above="@+id/eventDetailActivity_bottomRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.design.widget.AppBarLayout
android:id="@+id/main.appbar"
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/eventDetailActivity_collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary">
<RelativeLayout
app:layout_collapseMode="parallax"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/eventDetailActivity_speakerPictureImageView"
android:layout_width="match_parent"
android:layout_height="250dp"
android:scaleType="centerCrop"
android:src="@drawable/bg_profile" />
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/eventDetailActivity_nestedScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:layout_gravity="fill_vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:paddingBottom="7dp"
android:paddingTop="7dp"
android:id="@+id/eventDetailActivity_speakerInfoRl"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/orange">
<TextView
android:height="21dp"
android:id="@+id/eventDetailActivity_speakerLocationTextView"
android:layout_marginLeft="20dp"
android:textColor="@color/violet"
tools:text="Londres, Reino Unido"
android:textSize="12sp"
fontPath="fonts/Roboto-Medium.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true" />
<TextView
android:height="21dp"
android:id="@+id/eventDetailActivity_speakerEmailTextView"
android:layout_marginRight="20dp"
android:textColor="@color/violet"
tools:text="Londres, Reino Unido"
android:textSize="12sp"
fontPath="fonts/Roboto-Medium.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true" />
</RelativeLayout>
<TextView
android:id="@+id/eventDetailActivity_speakerDescriptionTextView"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:textColor="@color/grayA"
tools:text="Cuantos estilos de ilustración existen en el mundo? Nosotros conocemos 30, y te los queremos enseñar a todos en un workshop tan exagerado y tenaz..."
android:textSize="14sp"
android:lineSpacingExtra="@dimen/lines_spacing"
fontPath="fonts/Roboto-Light.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/plus_x3"/>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/eventDetailActivity_eventTitleTextView"
android:textColor="@color/grayA"
tools:text="Event Title"
android:textSize="16sp"
fontPath="fonts/Roboto-Bold.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/eventDetailActivity_eventDateTextView"
android:layout_marginTop="15dp"
android:textColor="@color/grayA"
tools:text="Event Date"
android:textSize="14sp"
fontPath="fonts/Roboto-Light.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/eventDetailActivity_eventLocationTextView"
android:layout_marginTop="10dp"
android:textColor="@color/grayA"
tools:text="Event Location"
android:textSize="14sp"
android:lineSpacingExtra="@dimen/lines_spacing"
fontPath="fonts/Roboto-Light.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
<include
android:layout_below="@+id/toolbar"
layout="@layout/tool_bar_dropshadow"
android:layout_height="wrap_content"
android:layout_width="match_parent"/>
<RelativeLayout
android:id="@+id/eventDetailActivity_bottomRelativeLayout"
android:background="@color/violet"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/eventDetailActivity_favoriteRelativeLayout"
android:clickable="true"
android:background="?attr/selectableItemBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/eventDetailActivity_favoriteTextView"
android:padding="16dp"
android:layout_centerInParent="true"
android:textColor="@color/orange"
android:text="@string/eventDetailActivity_addToFavs"
android:textSize="14sp"
fontPath="fonts/Roboto-Medium.ttf"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="11dp"/>
</RelativeLayout>
</RelativeLayout>
我尝试将 NestedScrollView 放在 Fragment 上,但这不起作用。