1. Define the two animation files that Popupwindow pops up and disappear, and place them under the Anim folder
Popup_enter.xml
<?XML version= "1.0" encoding= "Utf-8"?><Setxmlns:android= "Http://schemas.android.com/apk/res/android"> <TranslateAndroid:fromydelta= "100%p"Android:toydelta= "0"android:duration= "+"/> <AlphaAndroid:fromalpha= "0.0"Android:toalpha= "1.0"android:duration= "+"/></Set>
Popup_exit.xml
<?XML version= "1.0" encoding= "Utf-8"?><Setxmlns:android= "Http://schemas.android.com/apk/res/android"> <TranslateAndroid:fromydelta= "0"Android:toydelta= "100%p"android:duration= "+"/> <AlphaAndroid:fromalpha= "1.0"Android:toalpha= "0.0"android:duration= "+"/></Set>
Register these two animation effects in the 2.styles.xml file
<Resources> <stylename= "Popupanimation"> <Itemname= "Android:windowenteranimation">@anim/popup_enter</Item> <Itemname= "Android:windowexitanimation">@anim/popup_exit</Item> </style></Resources>
3. Add animations to the created Popopwindow
Inflater =nullnew Popupwindow (layout, WindowManager.LayoutParams.MATCH_ PARENT, WindowManager.LayoutParams.WRAP_CONTENT); Menu.setanimationstyle (r.style.popupanimation);//Add animation