LightProgress Animation

Tram Ho

Today, we will learn custom a view designed by Oleg Frolov on Dribble .

Mathematics things …

First we need to identify the axis for Light animation . As you can see, it is in the middle of the dot of the word ” i ” . We will perform this animation with text “Loading” and now we will calculate to find the coordinates:

  1. Calculate the width of text ( w1 ) with the word “i” ( Loadi )
  2. Calculate the width of text ( w2 ) when there is no word “i” ( Load )
  3. Calculate the width of the word “i” ( w3 ) with a double space of the word, w3 = w1 – w2
  4. Calculate pivotX coordinates: pivotX = w1 – w3 / 2
  5. Calculate the width of the word “i” ( w4 ) when there is no space. Suppose w4 = the diameter of the dot on the head i
  6. Calculate coordinates pivotY : pivotY = (-text.ascent – text.height + w4 / 2) . Can you find out about ascent, descent, …

I changed the word Light to Loading, but their calculation is the same.

Some drawing

To draw a bright white light, we need to calculate the trapezoidal structure.

Let’s light it up

Now we need to run the animation:

  • Create an animator object:

  • Update angles and invalidate view

  • Animation animation:

=> Not what we want?

Android PorterDuff.Mode

We will use PorterDuff.Mode to achieve the following result:

Code …

  • LightProgress.kt

  • CustomSpringInterpolator.kt

Share the news now

Source : Viblo