Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set button by a contour polygon? Android

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?

ImageButton

like image 801
Roman Avatar asked Jan 16 '13 15:01

Roman


1 Answers

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):

enter image description here

You can find the project here, it's pretty self explanatory. See if it helps you.

like image 78
user Avatar answered Nov 15 '22 12:11

user