Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom View Touch Events
    primarykey
    data
    text
    <p>I'm trying to implement a custom view in which the user can draw with his finger. Basically, I'm following <a href="http://corner.squareup.com/2010/07/smooth-signatures.html" rel="nofollow noreferrer">this tutorial</a>.</p> <p>Everything seems to be working nice, but, given the fact that I also have 2 buttons underneath the custom view like so:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/background_color" tools:context=".MainActivity" android:id="@+id/mainScreen" &gt; &lt;Button android:id="@+id/buttonSave" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true" android:text="@string/save" /&gt; &lt;Button android:id="@+id/buttonQuery" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentBottom="true" android:text="@string/query" /&gt; &lt;com.example.myapp.DrawView android:id="@+id/drawView" android:background="@color/red" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_above="@id/buttonSave" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>it actually draws even underneath the buttons and I'm having a hard time understanding why it doesn't capture only the touch events that occur on the DrawView and not outside it. Basically, I can't start the line from above the buttons, but once I start drawing on my view, I can even extend the line outside of it.</p> <p>As far as I can tell, the DrawView doesn't overflow beneath the buttons, <a href="https://stackoverflow.com/questions/11740252/aligning-controls">as discussed here</a> so I want to figure out what's going on. Do I really have to check if the events are out of bounds? Does it actually delegate all of the touch events to the currently focused view? Is there any way to change this behavior?</p> <p><a href="http://marakana.com/s/android_2d_graphics_example,1036/index.html" rel="nofollow noreferrer">This simple tutorial</a> doesn't have the described issue, but it draws point by point.</p> <hr> <p><strong>Update:</strong> Debugging the application, I determined that drawView has size 480x728, while mainScreen has 480x800, so they do not overlap. It continues to register touch events even if they are triggered outside of the drawView, once it has focus. This is what I'm trying to avoid and it would be nice to do it without passing the event coordinates through a big if statement...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload