Master Chief
Master Chief

Reputation: 2541

Non-intractable view

How can I make a view non-intractable. I have two canvas views stacked upon each other in a frame layout. Both canvas takes whole screen area and both are transparent. I want to show some PNG on the upper canvas, and let user draw on the lower canvas.

Problem is when user touches the screen, touch input is taken by upper canvas and since it does nothing (drawing in on the lower canvas), nothing happens.

I want the upper canvas to act just as an overlay view with no interactions and no events assigned, all of these should be consumed by lower view. If I set the upper overlay to invisible I can draw on lower canvas(as now lower canvas is receiving all the inputs).

Also canvas is not a standard canvas, but a custom one. It's derived directly from View class. But I think a derived view wouldn't cause problem. I just don't know how to proceed.

I tried using onTouch() on upper canvas and call onTouch() of lower canvas, did't worked. I am testing some other things like dispatchTouch() on 2 Buttons, but nothing seem certain to me. Help would be really appreciated.

Edit: Added XML Layout code

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.samsung.sdraw.CanvasView 
        android:id="@+id/canvas1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:onClick="cnvs1Click"
        android:text="Canvas1" />

    <com.samsung.sdraw.CanvasView 
        android:id="@+id/canvas2" 
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="Canvas2" 
        android:onClick="cnvs2Click"/>
</FrameLayout>

But I still think problem would be solved by View(s). Canvas is from S pen SDK

Upvotes: 1

Views: 209

Answers (2)

rspython
rspython

Reputation: 229

This might be a special case, haven't played to see if this is true, but normally in your onTouch events etc you just return false if you haven't handled the event, and the event bubbles up through each view's touch events until something returns true, which indicates it's handled hit.

if you make your one view (the upper layer) just return false from it's onTouch, the lower views onTouch should receive the event.

Upvotes: 1

thepoosh
thepoosh

Reputation: 12587

try in the XML to add to the root view

android:focusable="false"
android:focusableInTouchMode="false"

Upvotes: 0

Related Questions