There are two adjacent graphic buttons. If I use the method of calculation of the coordinates touch TouchEvent
, I have to create a large array of coordinates. Maybe there is another method?
Probably not the best solution but you could overlap two buttons each representing a part of the image(the black or white) and make the rest of the Button
's image transparent(the images will have the same dimensions for both buttons). You'll also need to extend the Button
class to override how the onTouchEvent
method handles the touch events, depending on the point where the touch happened being a transparent point or an "image" point. I've made a small sample project obtaining a Button
with two parts like below(ignore my design skills):
You can find the project here, it's pretty self explanatory. See if it helps you.
来源:https://stackoverflow.com/questions/14362027/how-to-set-button-by-a-contour-polygon-android