1

I want to create a layout with multiple recyclerviews that are scroll-synced (already working) and on top of the whole LinearLayout which contains these recyclerviews I want to have another recyclerview (overlay) also scroll-synced with the others (already working).

Now my problem: The overlay should ignore all Touch/Click-Events like it is not there. The views inside the linearlayour should react to them (working without overlay).

I tried to get it to work with onIntercerptTouchEvent and dispatch TouchEvents to the other views but I don't have a guess how to get it working.

My Layout: vertical_layout contains multiple Recyclerviews as mentioned

    <ScrollView
        android:id="@+id/scroll_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="false">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:baselineAligned="false">

            <LinearLayout
                android:id="@+id/vertical_layout"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:orientation="vertical"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toEndOf="@id/channels_layout">
            </LinearLayout>

            <CustomOverlayRecyclerView
                android:id="@+id/overlay_recycler_view"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:orientation="horizontal"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintEnd_toEndOf="parent"/>

            <LinearLayout
                android:id="@+id/channels_layout"
                android:layout_width="90dp"
                android:layout_height="match_parent"
                android:orientation="vertical"
                app:layout_constraintStart_toStartOf="parent">

            </LinearLayout>

        </androidx.constraintlayout.widget.ConstraintLayout>
    </ScrollView>
eMpTy
  • 30
  • 4

1 Answers1

1

To your custom RecyclerView add the following override:

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    return false;
}

This will prevent the custom RecyclerView from receiving further touch events and direct them to underlying views. See this Stack Overflow post for an explanation about how this works and links to other resources.

Cheticamp
  • 61,413
  • 10
  • 78
  • 131
  • I spent hours of hours searching for a solution and even read through the post you linked, but I didn't realize the solution is so simple... Thank you **very** much!! – eMpTy Apr 16 '19 at 18:58