Explain in detail the problem of loading circular pictures in glide and circleimageview in Android

Recently, I encountered a strange problem in the project. Glide and circleimageview used to load the circular avatar together. I found that the first time they were loaded, the first time they were loaded was a bitmap, which could only be loaded when you refreshed or entered for the second time. The reason is that circleimageview takes up the position. At this time, we have the following four solutions, no matter which one can be solved (pro test is feasible).

1. Do not use placeholders

Just comment out these two sentences of code.

Code when glide is loaded:

At this time, the in XML is still circleimageview, and the code is as follows:

2. Do not use default animation

Add a code:

The complete code when glide is loaded:

At this time, the in XML is still circleimageview, which has nothing to say. The code is as follows:

3. Use the circular loading mode of glide itself

Let's take a look at the code when glide is loaded. Note:

At this time, ivavator can use ordinary ImageView without introducing the third-party framework of circleimageview. (of course, you can still write it as circleimageview)

The sentence asbitmap() cannot be omitted, otherwise the following method will report an error.

At this time, the code in the XML is modified to ImageView, and the code is as follows:

4. The circular loading mode of glide itself is also used

This method is basically similar to the above. First, glidecircletransform inherits bitmaptransformation. The code is as follows:

The code when glide is loaded is as follows:

Note: ivavator at this time can still be ImageView (of course, you can still write circleimageview). The code is as follows:

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.

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
分享
二维码
< <上一篇
下一篇>>