Android PopupWindow 动画不工作

标签 android android-animation android-popupwindow

我在屏幕左上角单击按钮时显示 PopupWindow。但问题是,当我打开它时,它会显示得非常快,这意味着没有动画出现,但是当我关闭它时,它工作正常,这意味着它随着动画消失。

这是我的代码,请帮助我。

主类代码:

    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>

最佳答案

我在我的主要 Activity 主题中有这个标签。

<item name="android:windowDisablePreview">true</item>

我一删除它 - PopupWindow 的“in”动画就开始流畅地工作了。

关于Android PopupWindow 动画不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25398719/

相关文章:

android - 在 Xamarin Android 上使用 TabLayout 的 SetOnTabSelectdListerner?

android - LinearLayout 动画在第二次使用后不显示布局内的数据

android - 无法在 PopupWindow 中编辑 EditText 的文本

android - 如何在触摸位置附近显示自定义弹出窗口,就像我们使用 ContextMenu 时那样?

Android OrmLite - queryForId() 方法中的 OOM 错误

android - 如何为 Android Studio 2.2 模拟器更新 Google Play 服务?

android - 如何顺时针旋转ImageView

android - 定位纸屑

android - 如何使用动画从一个屏幕过渡到下一个屏幕