简体   繁体   中英

Android Overlapping Views and OnClick

I have a frame layout with some layout as the first element and another layout as the second (and thus over the top of the first). The top layout is semi-transparent, so you can see whatever is in the bottom layout beneath it:

<FrameLayout>
    <BottomLayout             
             android:onClick="BottomClicked">                 
             <Button android:onClick="ButtonClicked"/>
             <TextView/>
             <TextView/>
    </BottomLayout>
    <TopLayout
            android:background="@color/semi-transparent"
            android:onClick="TopClicked">
    </TopLayout>
</FrameLayout>

The bottom layout will change over time, with views being added/removed or set visible/invisible/gone. I'd like to be able to trigger the onClick event for both the top layout and also for anything that might be beneath it.

For example, if the user clicks on a portion of the top layout that is also over the button on the bottom layout, I'd like to trigger onClick for both the top layout and button on the bottom layout. At the moment, only onClick for the top layout is called

EDIT:

Edited the question to be more general/less specific

You could call the buttons click method from within the image click, or you can use an inset drawable which matches the size of your image to set as the buttons clickable area : See here

EDIT: If you can use the onTouch event instead of the onClick event, you can return false from the onTouch methods so that they propagate through the stack.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM