PopupWindow动画不工作

PopupWindow动画不工作

本文介绍了PopupWindow动画不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我要带一个动画一个不错的PopupWindow。我这样做是这样的:

I has a nice PopupWindow which I want to appear with an animation. I do it like this:

popup.setAnimationStyle(R.anim.appear);
popup.showAtLocation(popupMenuLayout, gravity, offsetX, offsetY);

我再建立一个监听器来改变动画:

I then set up a listener for changing the animation:

popup.setOnDismissListener(new PopupWindow.OnDismissListener(){
 @Override
 public void onDismiss(){
  popup.setAnimationStyle(R.anim.disappear);
 }
});

但是,嘿,它不会工作。无论是对RES /动画/显示:

But, hey, it won't work. Neither for res/anim/appear:

<translate xmlns:android="http://schemas.android.com/apk/res/android"
 android:fromYDelta="100%"
 android:toYDelta="0"
 android:duration="1000"
/>

也为RES /动画/消失:

Nor for res/anim/disappear:

<translate xmlns:android="http://schemas.android.com/apk/res/android"
 android:fromYDelta="0"
 android:toYDelta="100%"
 android:duration="1000"
/>

任何线索?

推荐答案

其实, PopupWindow.setAnimationStyle 愿与2项的样式。你需要有两个XMLS,每个都包含一个&LT;集&gt; ,一个用于显示和其他隐藏的窗口。当做到这一点,把下面的成片值/ styles.xml:

Actually, PopupWindow.setAnimationStyle expects a style with 2 entries. You'll need to have two xmls, each containing a <set>, one for showing and the other for hiding the window. When this is done, put the following piece into values/styles.xml:

<style name="AnimationPopup">
    <item name="android:windowEnterAnimation">@anim/popup_show</item>
    <item name="android:windowExitAnimation">@anim/popup_hide</item>
</style>

和设置您的动画风格,以 R.style.AnimationPopup 。这会做。

and set your animation style to R.style.AnimationPopup. That'll do.

我已经得到了这个信息https://github.com/lorensiuswlt/NewQuickAction3D该文件似乎并没有提到它。

I've got this information from https://github.com/lorensiuswlt/NewQuickAction3D the documentation didn't seem to mention it.

更新:

在2012年更新至Android SDK已经改变了XML语法。原 @android:windowEnterAnimation 现在变成了安卓windowEnterAnimation 。所以这个答案进行相应的更新。

An update to Android SDK in 2012 have changed XML syntax. The original @android:windowEnterAnimation now became android:windowEnterAnimation. So this answer is updated accordingly.

这篇关于PopupWindow动画不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 12:00