Android custom view to achieve floating leaf effect (III)
In the previous article, I learned about custom views and some methods. Here is a simple example of leaf fluttering
Main technical points
1. Add background picture Canvas. Drawbitmap()
2. Matrix animation class
3. Add matrix to canvas
step
1. Add yellow background color
2. Add background picture
Canvas.drawbitmap (Bitmap bitmap, rect SRC, rect DST, paint paint) adds a picture to the canvas
Rect SRC: picture clipping, null picture showing full screen, rectf DST: picture in canvas area
3. Add leaves
Canvas.drawbitmap (Bitmap bitmap, matrix, paint paint) adds an animated bitmap to the canvas
There is nothing defined in the matrix here, so the default is as follows, and the upper left corner is the leaf
4. Add matrix animation to leaves
Matrix function:
a. Translate translation
b. Rotate
c. Scale
d. Skew tilt
Matrix.posttranslate (float x, float y) is used here, and the upper left corner of the canvas is (0,0); XY is the absolute value of translation
Well, the effect is as follows. Since the matrix does not have the concept of animation time length, the sliding speed is set by calculating the displacement value through the time difference
If you don't paste the complete code, just copy the above code into a leafview extensions view, and then define several global variables in it.
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.