簡體   English   中英

在nestedscrollview中滾動多個水平回收器視圖,它們之間帶有視圖分隔符

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

我需要幫助..

這里是實際的:下面的 right-horizontal-recyclerview 只是滾動到 left-horizontal-recyclerview 后面。 它們之間實際上有一個分隔符。 所以我不期待這樣:

ss1

我希望當我從 right-rv 向左滾動(觸摸)時,帶有分隔符的 left-rv 也會滾動到屏幕的左邊緣

這是代碼

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

我已經嘗試了大約 6 個小時並在一些帖子中進行了研究,但沒有一個有幫助。 也許我需要一些其他關鍵字來找到確切的解決方案,請在此處注明

謝謝你...

您可以通過將 onScrollListener 添加到 Right Horizontal RecyclerView 並在 onScrolled() 回調中檢查您想要的滾動方向並將 Left Horizontal RecyclerView 滾動到左側來實現此行為,如下所示:

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
            }
       }
 });

暫無
暫無

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

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