Android shimmerlayout to achieve low light effect analysis

A while ago, I saw a very good animation effect on GitHub, called shimmerlayout, which is a layout used to realize the low light effect of the internal view.

How

By using porterduff, we can create a low light effect. Porterduff is a rendering mode in canvas rendering image processing. When we need to draw the graphic effect of area coverage, we can use this method to draw.

Here we use porterduff.mode.src_ In means that when drawing, the part where the upper and lower layers intersect is displayed, and this part displays the upper layer.

1) First, we need to draw the shimmer at the top layer. Here, we use the LinearGradient linear gradient renderer to draw the shimmer gradient effect. In order to make the gradient natural, we see that transparent colors are added at the front and rear ends of the code.

2) Then, we need to mix the layer of low light effect with the interface of the view itself, and use porterduff.mode.src_ In blend effect. First, how to draw the interface of the view itself is very simple. Directly call the drawing method super. Dispatchdraw (canvas) of the parent class, and then draw the layer of low light effect.

3) Finally, we found that the low light effect moves from left to right. How to achieve it?

By continuously shifting the position of localmaskbitmap, the effect of slow displacement of low light level is realized by controlling the offset value maskoffsetx.

The animation principle itself is very simple, but in terms of memory, because multiple bitmaps are created, if the current interface does not contain large images, the memory consumption is still very low. It is suitable for adding effects to relatively lightweight interfaces.

For more details, see the author's original introduction and GitHub

ShimmerLayout Github : https://github.com/team-supercharge/ShimmerLayout

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