简体   繁体   中英

scroll multiple horizonal recycler-view with view-separator between them inside nestedscrollview

i need help..

here the actual: the right-horizontal-recyclerview below is just scrolled behind the left-horizontal-recyclerview. they actually have a separator between them. so i'm not expecting like this:

ss1

i expect when i scroll (touching) from right-rv to left, the left-rv with the separator are also scrolled to the left-edge of the screen

this is the code

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
    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:orientation="vertical">

    <LinearLayout
        android:id="@+id/ll_carlist_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        /// many layout header here

    </LinearLayout>

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/srl_carlist"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:visibility="visible"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ll_carlist_header"
        app:layout_constraintVertical_bias="0.0">

        <androidx.core.widget.NestedScrollView
            android:id="@+id/nsv_carlist"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/ll_carlist_header"
            app:layout_constraintVertical_bias="0.0">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingBottom="33dp">

                <androidx.core.widget.NestedScrollView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    >

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        >

                        <androidx.recyclerview.widget.RecyclerView
                            android:id="@+id/rv_carlist_selectedfilter"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:orientation="horizontal"
                            android:paddingStart="16dp"
                            android:paddingTop="3dp"
                            android:paddingEnd="10dp"
                            android:paddingBottom="5dp"
                            android:clipToPadding="false"
                            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                            tools:itemCount="2"
                            tools:listitem="@layout/item_carlist_selectedfilter"
                            android:visibility="visible"
                            />


                        <View
                            android:id="@+id/v_carlist_selectedfilter_separator"
                            android:layout_marginTop="6dp"
                            android:layout_width="1dp"
                            android:layout_height="20dp"
                            android:background="@color/heather"
                            android:visibility="visible"
                            />

                        <androidx.recyclerview.widget.RecyclerView
                            android:id="@+id/rv_carlist_quickfilter"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:clipToPadding="false"
                            android:orientation="horizontal"
                            android:paddingStart="11dp"
                            android:paddingTop="3dp"
                            android:paddingEnd="16dp"
                            android:paddingBottom="5dp"
                            android:visibility="visible"
                            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
                            tools:itemCount="10"
                            tools:listitem="@layout/item_carlist_quickfilter" />



                    </LinearLayout>

                </androidx.core.widget.NestedScrollView>

                // other layout inside first nestedScrollView

            </LinearLayout>
        </androidx.core.widget.NestedScrollView>

    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

    /// other footer layout


</androidx.constraintlayout.widget.ConstraintLayout>

i have tried for approx 6 hours and research in some posts but none of them help. maybe i need some other keywords to find exact solution, please note it here

thank you...

You can achieve this behaviour by adding onScrollListener to the Right Horizontal RecyclerView and in onScrolled() callback check the scroll direction you want and scroll your Left Horizontal RecyclerView to the left like below:

rightRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
       @Override
       public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            if (dx < 0) {
                //Scrolling left
                leftRecyclerView.getLayoutManager().scrollToPosition(0);
            } else if (dx > 0) {
                //Scrolling right
            }
       }
 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM