How to realize imitating IOS10 Disc time Selector by Android
This article mainly explains the "Android how to achieve imitation IOS10 disc time selector", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Android how to achieve imitation IOS10 disc time selector" bar!
Project demonstration
Realization idea
Take 720 degrees as a cycle, 0 °360 °corresponds to 0 °12 hours, 360 °~ 720 °corresponds to 12 hours
Here, take the start time setting button as an example to talk about its sliding implementation:
Use the start time setting button as point A, the center of the dial as point O, and the finger touch point as point P. The size of ∠ AOP can be calculated by the arc tangent formula, and then the position of point A (that is, the angle of point A) can be updated with the continuous change of the position of the finger.
Line expression of / / coordinate system / / expression of line L1: float A1 = mCenterY-mStartBtnCurY;float b1 = mStartBtnCurX-mCenterX;float C1 = mStartBtnCurY * mCenterX-mCenterY * mStartBtnCurX;double D1 = (A1 * eventX + b1 * eventY + C1) / (Math.sqrt (A1 * A1 + b1 * b1)); / / expression of straight line L2: passing through the center point of the clock and perpendicular to the straight line l1 float a2 = b1 Float b2 =-A1; float c2 =-a2 * mCenterX-b2 * mCenterY; double D2 = (a2 * eventX + b2 * eventY + c2) / (Math.sqrt (a2 * a2 + b2 * b2)); / / with L1 as the baseline, the homeopathic semicircle is 0-180 degrees, counterclockwise semicircle is 0-negative 180 degrees double moveDegree = Math.toDegrees (Math.atan2 (D1, D2)); mStartDegree = (float) (mStartDegree + Math.floor (moveDegree)) MStartDegree = (mStartDegree < 0)? MStartDegree + mDegreeCycle: mStartDegree% mDegreeCycle; refreshStartBtnPositon (); invalidate (); Thank you for reading, the above is the content of "Android how to achieve imitation IOS10 disc time selector". After the study of this article, I believe you have a deeper understanding of how to achieve imitation IOS10 disc time selector in Android. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!