Android music player oscilloscope
The oscilloscope was taught by the teacher in college, but it has not been used when I came out to work. I gradually forget it. Now I'll study it again. Let's take a look at the renderings:
Here is a custom histogram, and then there is a button. When you click the button, the column will keep moving, similar to the beat of the oscilloscope in the music player.
Similar to the previous ways of customizing the view, the onsizechange() method and ondraw() method are rewritten. First, list the variables we want to use:
All the variables are here
Let's initialize the brush
Then assign a value to the variable in onsizechange()
Finally, draw the histogram
At this time, the oscilloscope of a music player has been completed, but this is static. Next, expose a method to the outside to refresh the view and achieve dynamic effects.
public void onStart() { postInvalidateDelayed(300); }
Redrawing the view every 300ms can have a better visual effect.
OK, finally, I'll post all the codes:
So far, it's all done.
The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.