A
A
Anton Misyagin2020-03-03 21:00:43
Android
Anton Misyagin, 2020-03-03 21:00:43

How to call click handlers on each of the overlapping views?

There are 2 View components, each one has a picture superimposed on the background, which is a crop. The components overlap. The end goal is to call a custom handler for each button when the green or yellow area is clicked. I imagine the solution as follows: When clicking anywhere in the view, the color of the clicked point should be taken, and if it is not transparent, then execute the code that handles the click. Accordingly, 2 problems arise
1. How to take the color in the view context at the click point. This means that I do not need the background color of the application, but the color of the view. In other words, if I click on a view with a yellow picture, I should get either yellow or transparent (the color must also contain alpha transparency) depending on whether I click on the yellow area or outside it.
2. If I click on an area where the views overlap, then two handlers from both views should be fired, each of which should figure out whether the color area or the transparent area was clicked (three different options are shown with red dots). In the first case, one of the handlers should find out that they clicked past the green area and end, and the second, realizing that they clicked on the yellow one, execute the code that corresponds to clicking on the yellow button. In the second case, both handlers must complete without affecting the click logic. Well, in the third, respectively, the opposite of case 1 - the logic of pressing the green button should be called. HOW IT WILL BE DONE - call both handlers, I CALL THAT HANDLER whose view lies higher along the Z axis) 5e5e9b47e916e222276508.png

I will accept another solution to the problem, tell me

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yuri, 2020-03-04
@YuryBorodkin

More like nikah. In principle, if you take a screenshot of the screen, save 1: 1, then find the tap point and see the color with your hands, you can file something, but this is really an unrealistic crutch.
Here, either count with your hands (for geometric shapes), or shove it all into one view and there already look where the tap hit.

D
Denis Zagaevsky, 2020-03-04
@zagayevskiy

Make one custom view, put spots on it in the background and implement Tachi on your own. There is no need to fence a garden from views.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question