donkingliang / ConsecutiveScroller

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

ConsecutiveScrollerLayout 包子類別 ConsecutiveScrollerLayout,滑動會不順暢 #308

Closed klps5603 closed 5 months ago

klps5603 commented 5 months ago

您好,請問一個問題

我使用 ConsecutiveScrollerLayout 包一層 ConsecutiveScrollerLayout ,在子 ConsecutiveScrollerLayout 中的 layout_recommend 吸頂之後,滑動子 ConsecutiveScrollerLayout 會導致滑動不順暢。

因為實際滑動的是外層的父類別 ConsecutiveScrollerLayout,在吸頂時讓子類別 ConsecutiveScrollerLayout isConsecutive=false ,雖然可以流暢滑動子類別,但是需要滑動父類別 ConsecutiveScrollerLayout (isConsecutive =true) 時,會中斷滑動效果,不好銜接起來。

請問大大有甚麼方法可以解決?謝謝

<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.donkingliang.consecutivescroller.ConsecutiveScrollerLayout
        android:id="@+id/scroller_layout_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white"
        android:fillViewport="true"
        android:orientation="vertical"
        app:adjustHeightOffset="76dp"
        app:autoAdjustHeightAtBottomView="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

            <TextView
                android:id="@+id/txt_recommend"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginHorizontal="16dp" />

            <LinearLayout
                android:id="@+id/layout_recommend"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                app:layout_isSticky="true"
                app:layout_scrollChild="@id/view_pager_home_recommend">

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

                    <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:tabIndicatorFullWidth="false"
                            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.ConsecutiveViewPager2
                    android:id="@+id/view_pager_home_recommend"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:paddingHorizontal="10dp" />

            </LinearLayout>

        </com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout>

    </com.donkingliang.consecutivescroller.ConsecutiveScrollerLayout>
donkingliang commented 5 months ago

在一个xml布局里,没有必要用到ConsecutiveScrollerLayout嵌套ConsecutiveScrollerLayout。而且你什么把ConsecutiveViewPager2放到吸顶布局里。那不是整个布局都吸顶了吗

klps5603 commented 5 months ago

對,我正好也意識到這點,現在調整 xml 只有一個 ConsecutiveScrollerLayout , 解決了滑動不順的問題,謝謝