Method of realizing custom ImageView circle function by Android programming

This paper describes the method of realizing the function of custom ImageView circle chart by Android programming. Share with you for your reference, as follows:

First of all, I would like to thank the open source project universal image loader image loading framework. I've seen the time frame source code for some time before, but I don't have time to summarize the knowledge points.

Today, the project encountered the need to implement the editing and display of the round head image. Universal has provided the display. The roundedbitmapdisplay class implements the round chart function. Looking at its code, you can find that it is drawable

In fact, to sum up, the implementation steps of the above circular diagram are:

1. Initialize the bitmap shader bitmapshader class through bitmap 2, calculate the rect of the original image of bitmap 3, calculate the rect required to place the image 4, compress the two rects with matrix class, and then copy them to the bitmapshader shader. Finally, canvas painting. (at the beginning, I always thought that shader meant shadow, but it meant shader. In fact, this translation is very important for me to understand the code, so don't take it for granted. Be diligent. This is a necessary element for good programmers.)

The last thing I want to implement is to inherit the ImageView to implement the circular graph

It was not standardized at the beginning. We directly added some required objects in the OnDraw method. Lint reminded us of the warning of avoid object allocations during draw / layout operations (preallocate and reuse instead). Because OnDraw will be called continuously, if the new object is always called, it will eat memory. Therefore, in order to avoid duplicate new objects, empty judgment is performed according to your own needs. Optimize the code according to your own requirements. Sometimes, in order to meet the requirements, there is no way to avoid repeating the new object in the OnDraw method.

Conclusion: refer to excellent open source projects and do the right thing in the right way!

More readers interested in Android related content can view the special topics of this site: summary of Android graphics and image processing skills, introduction and advanced tutorial of Android development, summary of Android debugging skills and common problem solving methods, summary of Android basic component usage, summary of Android view skills, summary of Android layout skills, and Android control usage summary

I hope this article will help you in Android programming.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>