Android PopupWindow动画无法正常工作 [英] Android PopupWindow Animation not working
本文介绍了Android PopupWindow动画无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从屏幕的左上角单击按钮时显示PopupWindow.但是问题是,当我打开它时,它显示的非常快,这意味着没有动画发生,但是当我关闭它时,它的工作正常,这意味着它随着动画消失了.
I am showing PopupWindow on button click from top-left corner of the screen. But the problem is, when I am opening it, it will shown very fast, that means no animation occurs, but when I am closing it, its working fine, that means it is disappearing with animation.
这是我的代码,请帮助我.
Here is my code, please help me.
主类代码:
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()));
// popup.showAtLocation(layout, Gravity.LEFT | Gravity.TOP, rect.left -
// v.getWidth(), getDeviceHeight() - rect.top);
popup.showAtLocation(layout, Gravity.TOP | Gravity.LEFT, rect.left, rect.bottom);
我的style.xml
<?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>
我的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>
我的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>
推荐答案
我在我的主要活动主题中使用了这个标签.
I was having this tag in my main Activity Theme.
<item name="android:windowDisablePreview">true</item>
我将其删除后-PopupWindow的输入"动画开始正常运行.
As soon as I removed it - "in" animation for PopupWindow started to work smooth.
这篇关于Android PopupWindow动画无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文