簡體   English   中英

如何在協調器布局內使用嵌套滾動視圖進行平滑滾動

[英]how to do smooth scrolling with nested scroll view inside coordinator layout

<android.support.design.widget.CoordinatorLayout 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"
    android:background="@android:color/background_light"
    android:fitsSystemWindows="true">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/main_collapsing"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleTextAppearance="@android:color/transparent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:title="">

            <fragment xmlns:tools="http://schemas.android.com/tools"
                android:id="@+id/map"
                android:name="com.google.android.gms.maps.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context="com.mydermacy.www.beyou.activities.CompareClinicsActivity" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/main_toolbar_clinics"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                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:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">


    <android.support.v7.widget.RecyclerView
            android:id="@+id/rc_clinic_compare"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:behavior_overlapTop="184dp"
            android:background="@color/background" />

    </android.support.v4.widget.NestedScrollView>

    <!--app:layout_behavior="@string/appbar_scrolling_view_behavior" />-->

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

我有CoordinatorLayout作為rootview的布局,在里面我有兩個子視圖AppBarLayoutNestedScrollView 我無法進行平滑滾動。 可以做些什么來實現平滑滾動?

CoordinatorLayoutCollapsingToolbarLayout平滑滾動是錯誤 ,谷歌仍然沒有修復它。 :|

刪除NestedScrollView 使用app:layout_behavior="@string/appbar_scrolling_view_behavior" RecyclerView app:layout_behavior="@string/appbar_scrolling_view_behavior"這就夠了並修復。

你可以使用第三方庫: smooth-app-bar-layout

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="match_parent">

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/main_collapsing"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:expandedTitleTextAppearance="@android:color/transparent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        app:title="">

        <fragment xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context="com.mydermacy.www.beyou.activities.CompareClinicsActivity" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/main_toolbar_clinics"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            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:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">


    <android.support.v7.widget.RecyclerView
        android:id="@+id/rc_clinic_compare"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:behavior_overlapTop="184dp"
        android:background="@color/background" />

</android.support.v4.widget.NestedScrollView>

<!--app:layout_behavior="@string/appbar_scrolling_view_behavior" />-->
</RelativeLayout>
</ScrollView>

我從循環視圖中刪除了嵌套的滾動視圖和app:behavior_overlapTop =“184dp”,所以問題也解決了我添加了app:layout_behavior =“@ string / appbar_scrolling_view_behavior”來回收視圖感謝您的幫助

暫無
暫無

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

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