Imitating android native shortcut UI effect, androidshortcut
Imitating android native shortcut UI
Let's take a look. The picture is a bit fuzzy.
The first time I saw the native cutting animation, I felt very agile and liked it. I just had similar needs in the project, so I made a similar one myself, the effect is still a little different from that of native.
To write this effect, consider the following:
* Because this is an operable menu, it is best to use PopupWindow as the most carrier.
* What parent container is used? Whether to use ViewGroup or ListView/RecyclerView, first consider the scalability of this effect. It is not suitable for scenarios with many entries because the animation takes a long time after there are many entries, the first time a user uses it, the user will be amazed. After a long time, the user will lose the freshness, And the UI effect will not be good after there are too many entries. Therefore, after comprehensive consideration, the user still chooses to directly use LinearLayout as the parent container.
* How do I implement a search animation? Observe the animation carefully and you will find that the animation is executed progressively, and the execution time of each animation is different. In fact, you can also customize the entry control, generate the corresponding number of control entries based on the data source and dynamically add them to our LinearLayout. Then, because the entries are gradually expanded, we execute the animation for loop, the animation delay time varies according to the position of the entry.
Public void expand (int itemAnimationTime, int itemAnimationGap ){
For (int I = 0; I <getChildCount (); I ++ ){
If (getChildAt (I) instanceof ShortcutView ){
(ShortcutView) getChildAt (I). expand (true, itemAnimationTime, (getChildCount ()-I) * itemAnimationGap );
}
}
IsExpanded = true;
}
'''
* The last and most troublesome problem is the background. Some people say that it is not easy to get a. 9 image, but if you observe the effect carefully, you will know that it is not that easy.
1. The background is shadow and has a pressing effect.
2. Arrow Animation
After thinking twice, I decided to write a custom drawable and use the code to draw the background.