A dialog box that pops up from the click was recently implemented with the following result:

1. Take that

Options for Dialog implementation include Dialog, PopupWindow, and Activity. They both support custom pop-up and disappear animations. They can both implement custom animations.

WindowAnimation Transition ShareElement Transition
Dialog support Does not support Does not support
PopupWindow support support Does not support
Activity support support support

WindowAnimation animations must be defined in styles. XML. WindowEnterAnimation and windowExitAnimation cannot be set dynamically by code. It means that once the windowAnimation is set, the animation is fixed, obviously not enough to make a pop-up animation from a click. Rule out the Dialog. Activity supports both transition animation and shared element transition animation. After some attempts, I found that although the Activity supports rich transition animation, it is not suitable to complete the function of the scene, and finally decided to use PopupWindow to implement this function.

2. The following

The feature of this animation is to enlarge the animation from the finger click and move the center point of the dialog box to the center of the screen. The core code is as follows

3. The solution

The final code

4. Obtain the complete source code

Follow the wechat public account “bytecode” and reply to “dialog box” to obtain the complete source code