SoFunction
Updated on 2025-03-11

Animation effect of popupwindow entry and exit in Android

I will just post code to you without saying much nonsense. The specific code is as follows:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:andro> 
  <translate 
    android:fromXDelta="0" 
    android:toXDelta="0" 
    android:fromYDelta="120" 
    android:toYDelta="0" 
    android:duration="500" /> 
</set>

Then define the animation file that disappears:

&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;set xmlns:andro&gt; 
  &lt;translate 
    android:fromXDelta="0" 
    android:toXDelta="0" 
    android:fromYDelta="0" 
    android:toYDelta="120" 
    android:duration="500" /&gt; 
&lt;/set&gt;
PopupWindowThe animation display effect is throughsetAnimationStyle(int id)Method settings,inidFor onestyleofid,So we need to set an animation style in the file:
&lt;style name="popwin_anim_style"&gt;
   &lt;item name="android:windowEnterAnimation"&gt;@anim/menushow&lt;/item&gt;
   &lt;item name="android:windowExitAnimation"&gt;@anim/menuhide&lt;/item&gt;
&lt;/style&gt;

Then set PopupWindow in the program to:

PopupWindow pop = new PopupWindow(view, .FILL_PARENT, .WRAP_CONTENT);
(.popwin_anim_style);

The above is the animation of popupwindow entry and exit in Android introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!