Android弹出窗口动画无法工作

3

我希望在按钮点击时从屏幕左上角显示PopupWindow。但问题是,当我打开它时,它会非常快地显示,也就是说没有动画效果,但当我关闭它时,它能够正常工作,也就是说它会消失并且有动画效果。

下面是我的代码,请帮我看看。

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()));

            // 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>

你解决问题了吗? - DaveNOTDavid
是的,我已经解决了。@DaveNOTDavid - Pratik Dasa
1个回答

3
我在我的主Activity主题中使用了这个标签。
<item name="android:windowDisablePreview">true</item>

一旦我将其移除,“PopupWindow”的“in”动画就开始流畅运行。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接