I have this architecture (ViewGroup with a View and RecyclerView):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.wacom.matchapoc.MainActivity"
tools:showIn="@layout/activity_main">
<com.wacom.matchapoc.view.SmartRecyclerView
android:id="@+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical" />
<com.wacom.matchapoc.view.DrawingView
android:id="@+id/drawingView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
The DrawingView
is ontop of the RecyclerView
and has an Overridden onTouch()
event, so that when isEnableDrawing()
flag is true (you can set it from the settings in the main activity) it handles the touch_down/move/up events so that you can draw over the elements in the RecyclerView
.
What I want to do now is essentially to link the user-made drawings on the DrawingView
to the child elements (text, pictures etc.) of the RecyclerView
. To do that I need to know which child element of the RecyclerView
is under the initial touch_down(x,y)
coordinates, tag it and then continue drawing.
Currently I have these problems:
getFocusedChild()
method of the RecyclerView
will correctly return the child element that is under the touch_down(x,y)
;RecyclerView
, I need to not consume it in the DrawingView
, then tag the child element in the RecyclerView
and not consume it again, then return it to the DrawingView
and continue with the drawing.This is proving rather difficult for me since I've only recently started Android programming and am not all that familiar with the API and how it works.
Any suggestions about how to link/tag the child elements so that I can easily know which drawing/path belongs to which child element would be most welcome.
Apparently there's a method in RecyclerView
called findChildViewUnder() which does exactly what I needed.