I show PopupWindow when I click a button in the upper left corner of the screen. But the problem is that when I open it, it will be shown very quickly, this means that the animation does not happen, but when I close it, it works fine, it means that it disappears with the animation.
Here is my code, please help me.
Main class code :
LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = layoutInflater.inflate(R.layout.eosos_maptype_popup, null); final TextView txtContacts = (TextView) layout.findViewById(R.id.txtContacts); final TextView txtFeatured = (TextView) layout.findViewById(R.id.txtFeatured); final PopupWindow popup = new PopupWindow(CalendarView.this); popup.setAnimationStyle(R.style.animation); popup.setContentView(layout); popup.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); popup.setWidth(WindowManager.LayoutParams.WRAP_CONTENT); popup.setFocusable(true); popup.setBackgroundDrawable(new BitmapDrawable(getResources()));
My .xml style
<?xml version="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="animation" parent="android:Animation"> <item name="@android:windowEnterAnimation">@anim/popup_show</item> <item name="@android:windowExitAnimation">@anim/popup_hide</item> </style> </resources>
My popup_show.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="-100%" android:toXDelta="0" android:duration="1000"/> </set>
My popup_hide.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromXDelta="0" android:toXDelta="-100%" android:duration="1000"/> android:duration="200"/> --> </set>
source share