setAnimationStyle 不适用于 Android 2.3.5
我编写了一个在弹出窗口中使用 setAnimationStyle 的代码,当我在运行 Android 2.2 操作系统的 Galaxy 1 设备上检查代码时,一切都运行良好。但当我在运行 Android 2.3.5 操作系统的 Galaxy 2 设备上尝试时,动画不再起作用。
这是代码。 谢谢。
这是 style.xml 中的动画定义
<style name="AnimationPopup" parent="android:Animation">
<item name="@android:windowEnterAnimation">@anim/popup_menu</item>
<item name="@android:windowExitAnimation">@anim/fadeout</item>
</style>
这是位于 res/anim 的动画
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="100%"
android:toYDelta="0"
android:duration="300"
/>
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:interpolator="@android:anim/accelerate_interpolator"
android:duration="500"/>
</set>
这是我在活动中使用的代码:
_menu = new PopupWindow(googlePopupInflator);
_menu.setOutsideTouchable(true);
_menu.setAnimationStyle(R.style.AnimationPopup);
_menu.showAtLocation(getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
I wrote a code that uses setAnimationStyle in a popup window, when i check the code on a Galaxy 1 device running Android 2.2 OS everything worked great. But when i try it on the Galaxy 2 device running Android 2.3.5 OS the animation doen't work any more.
here is the code .
Thanks.
this is animation definition in style.xml
<style name="AnimationPopup" parent="android:Animation">
<item name="@android:windowEnterAnimation">@anim/popup_menu</item>
<item name="@android:windowExitAnimation">@anim/fadeout</item>
</style>
this is the animation located at res/anim
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromYDelta="100%"
android:toYDelta="0"
android:duration="300"
/>
<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0" android:toAlpha="0.0" android:interpolator="@android:anim/accelerate_interpolator"
android:duration="500"/>
</set>
this is the code i use in the activity :
_menu = new PopupWindow(googlePopupInflator);
_menu.setOutsideTouchable(true);
_menu.setAnimationStyle(R.style.AnimationPopup);
_menu.showAtLocation(getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在迁移到 2.3.4 时遇到了同样的问题
解决方法:对 PopupWindow 内的控件进行动画处理。
我的 PopupWindow 包含一个主线性布局和其中的子线性布局。
我尝试为主要线性布局设置动画 - 没有成功。
然后我尝试对子布局进行动画处理并成功了。对它们中的每一个应用一个平移动画(每个动画的不同实例),并在显示 PopupWindow 后立即对它们进行动画处理。它们同时滑入其中 - 最终效果 - 就好像 PopupWindow 本身是动画的。
I encountered same problem on moving to 2.3.4
Made a workaround: Animate the controls inside the PopupWindow.
My PopupWindow contained a main linear layou and inside it child linera layouts.
I tried to animate the main linear layout - didn't succeed.
Then I tried animating the child layouts and succeeded. Applied to each one of them a translate animation (a different instance of the animation to each one) and I animated them right after showing the PopupWindow. They all slide in them same time - net effect - as if the PopupWindow was animated by itself.