1.定义PopupWindow弹出与消失的两个动画文件,放在anim文件夹下
popup_enter.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="100%p" android:toYDelta="0" android:duration="1000"/> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="1000"/> </set>
popup_exit.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="0" android:toYDelta="100%p" android:duration="1000"/> <alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="1000"/> </set>
2.styles.xml文件中注册这两个动画效果
<resources> <style name="popupAnimation"> <item name="android:windowEnterAnimation">@anim/popup_enter</item> <item name="android:windowExitAnimation">@anim/popup_exit</item> </style> </resources>
3.为创建的PopopWindow添加动画
inflater = getLayoutInflater(); layout = inflater.inflate(R.layout.menu, null); menu = new PopupWindow(layout, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); menu.setAnimationStyle(R.style.popupAnimation);//添加动画
PopupWindow添加动画效果,布布扣,bubuko.com
原文:http://www.cnblogs.com/jsczljh/p/3825793.html