首先定义显示效果的动画文件:
<?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>
add:
// the following 3 lines` codes are used to make sure the popupwindow can be closed when touch the other place
//out of the range of the popuewindow
//mWeatherPopuwindow.setFocusable(true);
//mWeatherPopuwindow.setOutsideTouchable(true);
//mWeatherPopuwindow.setBackgroundDrawable(new BitmapDrawable(getResources(), (Bitmap) null));