簡體   English   中英

Android NestedScrollView在CoordinatorLayout中平滑滾動

[英]Android NestedScrollView smooth scroll in CoordinatorLayout

我正在使用示例ScrollingActivity(包含在SDK中)來測試視差行為。 該示例在CoordinatorLayout中使用NestedScrollView。 當我從屏幕底部向上滾動時; 滾動停在工具欄上(即使我的滾動速度很快)。 正如您在附加圖像中看到的那樣,需要多個滾動來顯示擴展的AppBarLayout。

在此輸入圖像描述

我需要一個平滑的滾動,供用戶查看擴展的AppBarLayout。 有趣的是, 如果我使用RecyclerView而不是NestedScrollView則不會發生此問題

我正在使用構建工具23.0.3。 這是布局XML:

<?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="me.deepakmishra.swipetests.ScrollingActivity">

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    <android.support.v4.widget.NestedScrollView
        android:layout_gravity="fill_vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:context="me.deepakmishra.swipetests.ScrollingActivity"
        tools:showIn="@layout/activity_scrolling">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/text_margin"
        android:text="@string/large_text" />
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        app:layout_anchor="@id/app_bar"
        app:layout_anchorGravity="bottom|end"
        app:srcCompat="@android:drawable/ic_dialog_email" />

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

我無法使用CoordinatorLayout實現這一點,主要是因為我無法獲得同時封裝速度和位置的事件。 CoordinatorLayout在單獨的回調中提供速度和位置,使用它們會導致運動結束。

我使用自定義處理程序以傳統方式實現視差效果,以跟蹤所有滾動/拖動操作。

將android:fillViewport =“true”和android:layout_gravity =“fill_vertical”添加到您的NestedScrollView中。 希望這會幫助你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM