donkingliang / ConsecutiveScroller

ConsecutiveScrollerLayout是Android下支持多个滑动布局(RecyclerView、WebView、ScrollView等)和普通控件(TextView、ImageView、LinearLayou、自定义View等)持续连贯滑动的容器,它使所有的子View像一个整体一样连续顺畅滑动。并且支持布局吸顶功能。
Apache License 2.0
2.69k stars 357 forks source link

CoordinatorLayout 內嵌 ConsecutiveScrollerLayout,滑動會不順 #310

Closed klps5603 closed 2 months ago

klps5603 commented 3 months ago

您好,我的佈局大致如下

  <androidx.coordinatorlayout.widget.CoordinatorLayout
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <com.google.android.material.appbar.AppBarLayout
             android:id="@+id/appbar"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:background="@android:color/transparent">

        </com.google.android.material.appbar.AppBarLayout>

    <com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout
        android:id="@+id/scroller_layout_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:fillViewport="true"
        app:autoAdjustHeightAtBottomView="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <HorizontalScrollView
            android:id="@+id/scroll_view_tab_layout_recommend"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:fillViewport="true"
            android:paddingHorizontal="16dp"
            app:layout_isSticky="true">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <com.google.android.material.tabs.TabLayout
                    android:id="@+id/tab_layout_recommend"
                    android:layout_width="match_parent"
                    android:layout_height="?actionBarSize"
                    app:tabGravity="fill"
                    app:tabIndicator="@drawable/corners_strawberry_5"
                    app:tabIndicatorColor="@null"
                    app:tabIndicatorHeight="3dp"
                    app:tabMode="fixed"
                    app:tabRippleColor="@null"
                    app:tabSelectedTextColor="@color/strawberry"
                    app:tabTextAppearance="@style/TabTextAppearance"
                    app:tabTextColor="@color/color_050505" />

                <View
                    android:id="@+id/view_tab_layout_recommend_line"
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/color_e3e3e3" />

            </LinearLayout>

        </HorizontalScrollView>

        <com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white">

            <com.liontravel.android.consumer.ui.main.home.HomeRecommendConsecutiveViewPager2
                android:id="@+id/view_pager_home_recommend"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        </com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout>

    </com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

view_pager_home_recommend 往上滑到離頂部一段距離,會卡住不能滑到頂,放開手再滑才能繼續往上滑 看起來需要往上滑,超過一段距離才正常,請問要如何只滑動 view_pager_home_recommend 的前提下,順暢的捲動到吸頂狀態

donkingliang commented 3 months ago

可能是嵌套滑动的事件断了,你可以试一下在ConsecutiveScrollerLayout的onTouchEvent方法的ACTION_MOVE加一下这段代码 if (!hasNestedScrollingParent(ViewCompat.TYPE_TOUCH)) { startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL, ViewCompat.TYPE_TOUCH); }

如果你没有引用源码,你可以通过继承ConsecutiveScrollerLayout来修改

klps5603 commented 2 months ago

最後實務上不需要 AppBarLayout 了,因此沒用上大大的解法,這題先到這裡,謝謝