Android realizes the effect of rolling scale
origin
Recently, I'm helping people make a pedometer, which involves the collection of height, weight and other information; I refer to the implementation of many apps and feel that the sliding scale in "music power" is more elegant. Therefore, the app was decompiled, and it was found that it was implemented in the form of pictures, that is, a graduated picture was embedded in Scrollview. Personally, I think this method is too inflexible and relies heavily on art workers, so I want to customize a scale control.
requirement analysis
Knowledge points involved
Final effect
Since GIF cannot be embedded in the simple book, in order not to affect the effect, please move to GitHub to check. If you think it's good, help give a star^_^ https://github.com/LichFaker/ScaleView
Implementation process
1. Create a new class: horizontalscalescrollview, which inherits from view
2. Get custom attribute in constructor:
3. Override onmeasure to calculate the middle scale
4. Override OnDraw to draw scales and pointers
Handling sliding events
Final description
The above is only for the realization of horizontal sliding scale. The principle of vertical sliding is the same. It has been realized in the source code, and there are many imperfections, such as: