Android achieves cool checkbox effect

First, paste the effect picture of the implementation:

The effect of GIF may be a little too fast, and the effect will be better on the real machine. Our main idea is to use attribute animation to dynamically draw the selected state and the drawing process of checkmarks. Seeing the above renderings, I believe everyone can't wait to try. Let's start.

The first step of customizing the view: customize the properties.

We put Check@R_399_2419 @Named SmoothCheck@R_399_2419 @, defines several properties to be used, etc. This step is very simple. I believe everyone is skilled.

Next, take a look at onmeasure (int widthmeasurespec, int hightmeasurespec):

It was measured at first SmoothCheck@R_399_2419 @The default width and height are arbitrarily defined. Of course, you can modify and improve it yourself. Then, set the radius and so on. The last startpoint, breakpoint and endpoint correspond to the three checked points when selected (as for why these numbers are, they are all empirical values); Downlength is the distance between startpoint and breakpoint, and the corresponding uplength is the distance between breakpoint and endpoint. This is the following illustration:

Before looking at OnDraw (canvas), let's first look at two groups of animation, namely, the animation in the selected state and the animation in the unselected state:

These two sets of animations are clicking SmoothCheck@R_399_2419 @Called when. Similarly, the progress of animation execution is obtained during animation execution, and then postinvalidate() is called; Give Way SmoothCheck@R_399_2419 @Redraw. After reading this, it's the ultimate trick OnDraw (canvas):

The logic in OnDraw (canvas) code is basically annotated. The main reason is that it is easier to understand the principle. When drawing a cross check, you should distinguish which state is currently drawing a cross check, and then do corresponding processing to draw lines. The rest is simple. about SmoothCheck@R_399_2419 @That's about it.

It's posted below SmoothCheck@R_399_2419 @Complete code of:

summary

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. If you have any questions, you can leave a message.

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