首先定义显示效果的动画文件:
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android">
- <translate
- android:fromXDelta="0"
- android:toXDelta="0"
- android:fromYDelta="120"
- android:toYDelta="0"
- android:duration="500" />
- </set>
然后定义消失效果的动画文件:
- <?xml version="1.0" encoding="utf-8"?>
- <set xmlns:android="http://schemas.android.com/apk/res/android">
- <translate
- android:fromXDelta="0"
- android:toXDelta="0"
- android:fromYDelta="0"
- android:toYDelta="120"
- android:duration="500" />
- </set>
PopupWindow的动画显示效果是通过setAnimationStyle(int id) 方法设置的,其中id为一个style的id,所以我们要在styles.xml文件中设置一个动画样式:
- <style name="popwin_anim_style">
- <item name="android:windowEnterAnimation">@anim/menushow</item>
- <item name="android:windowExitAnimation">@anim/menuhide</item>
- </style>
然后在程序中为PopupWindow设置就成:
- PopupWindow pop = new PopupWindow(view, ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- pop.setAnimationStyle(R.style.popwin_anim_style);