Android Custom View: Draw Roulette sector and add a click event sector


I. Introduction

Remember to write a demo fifty-six years ago, with canvas.drawArc()the rotation and canvas and other implements, drawing roulette, not the original path, do not know how to engage the click event of the sector ... ... forcibly shelved later learned Path, also I did not go and change it. Kotlin rewrite the past two days with the next, path to play again, but was written when clicked fan-shaped region match, and after the rotation angle, preconceived would enter into a misunderstanding,

val bounds = RectF()
path.computeBounds(bounds, true)

Thinking with

matrix.postRoate(angle) 
mapRect(bounds)

Obtaining a rectangular rotated, to build Region, to match the sector hit area after rotation. Thus embarked on a road of no return ...
and finally found the center point of the rotary press, the original rectangle R, will become tilted, then left the original coordinates, visually it seems, may be left / right / top / bottom, uh, yes , (due to the different angles) may; Debug and through, the found values array matrix, appears sacle value; therefore, seeing this result, thought, should be in the rotation matrix, where this time it is the original R the outer rectangle is written back to the R, so there will scale the scale value ...

The final solution but very simple, that is path.addArc()the startAnglevalue, plus the angle of rotation on it.


II. Effect of FIG.

roulette view

Because of custom properties, there are other util codes, the overall code is not a quote. GH Portal


Published 400 original articles · won praise 364 · Views 1.62 million +

Guess you like

Origin blog.csdn.net/jjwwmlp456/article/details/105354976