溶解过渡(alpha动画)仅适用于淡入而不是淡出

时间:2017-09-06 20:37:50

标签: android android-animation android-dialog

我正在设置一个Dialog,以便在打开时产生一些效果。 我在OnClickListener中实现了它,如下所示:

final Dialog nagDialog = new Dialog(DetailActivity.this,
                        R.style.FullscreenDialogTheme);
                nagDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                nagDialog.setCancelable(true);
                nagDialog.setContentView(R.layout.fullscreen_image);
                PhotoView ivPreview = (PhotoView)nagDialog.findViewById(R.id.iv_preview_image);
                ivPreview.setImageBitmap(mWallpaperBitmap);
                nagDialog.show();

这种风格:

<style name="FullscreenDialogTheme" parent="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
    <item name="android:windowAnimationStyle">@style/MyAnimation.Window</item>
</style>
<style name="MyAnimation.Window" parent="@android:style/Animation.Activity">
    <item name="android:windowEnterAnimation">@anim/anim_in</item>
    <item name="android:windowExitAnimation">@anim/anim_out</item>
</style>

使用此动画:

anim_in

<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
    android:interpolator="@android:anim/linear_interpolator"
    android:fromXScale="0.0"
    android:toXScale="1.0"
    android:fromYScale="0.0"
    android:toYScale="1.0"
    android:fillAfter="false"
    android:startOffset="150"
    android:duration="200"
    android:pivotX = "50%"
    android:pivotY = "30%"
    />
<translate
    android:fromYDelta="0%"
    android:toYDelta="0%"
    android:startOffset="200"
    android:duration="300"
    />
<alpha
    android:duration="800"
    android:fromAlpha="0.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:toAlpha="1.0" />

anim_out

<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
    android:interpolator="@android:anim/linear_interpolator"
    android:fromXScale="1.0"
    android:toXScale="0.0"
    android:fromYScale="1.0"
    android:toYScale="0.0"
    android:fillAfter="false"
    android:duration="150"
    android:pivotX = "50%"
    android:pivotY = "30%"
    />
<translate
    android:fromYDelta="0%"
    android:toYDelta="0%"
    android:duration="200"
    />
<alpha
    android:duration="500"
    android:fromAlpha="1.0"
    android:interpolator="@android:anim/accelerate_interpolator"
    android:toAlpha="0.0" />

不幸的是,只有当我打开对话框时才会正确显示alpha动画,当我关闭它时,translatescale动画按预期工作,但没有alpha淡入淡出。感谢。

0 个答案:

没有答案