How to set button by a contour polygon? Android

后端 未结 1 397
旧时难觅i
旧时难觅i 2020-12-11 05:53

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. M

相关标签:
1条回答
  • 2020-12-11 06:39

    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.

    0 讨论(0)
提交回复
热议问题