1,在res/anim 下定义popupwindow 出现和消失的动画
①出现的动画popupwindow_show.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <alpha xmlns:android="http://schemas.android.com/apk/res/android" 3 android:duration="1000" 4 android:fromAlpha="0.0" 5 android:fillAfter="true" 6 android:interpolator="@android:anim/accelerate_decelerate_interpolator" 7 android:toAlpha="1.0" > 8 </alpha>
②消失的动画popupwindow_dismiss.xml
1 <?xml version="1.0" encoding="utf-8"?> 2 <alpha xmlns:android="http://schemas.android.com/apk/res/android" 3 android:duration="1000" 4 android:fromAlpha="1.0" 5 android:fillAfter="true" 6 android:interpolator="@android:anim/accelerate_decelerate_interpolator" 7 android:toAlpha="0.0" > 9 </alpha>
2,popupwindow的动画是通过方法setAnimationStyle(R.style.popupwindow_anim_style);设置的。
所以在res/values 下的styles.xml 中 添加
1 <style name="popupwindow_anim_style"> 2 <item name="android:windowEnterAnimation">@anim/popupwindow_show</item> 3 <item name="android:windowExitAnimation">@anim/popupwindow_dismiss</item> 4 </style>
3,应用到代码中
mPopupWindow.setAnimationStyle(R.style.popupwindow_anim_style);
mPopupWindow.update();