动画在自定义对话框中不起作用

Coa*_*key 6 android android-animation customdialog android-dialog

我已经按照此链接制作了自定义对话框,并且它的工作正常。但后来我想添加动画,使它看起来像从屏幕的顶部到底部。所以我搜索了这两个动画并找到了它们并将它们放在anim文件夹中。所以为了在我的自定义对话框中应用它们,我稍微改变了构造函数。我在自定义对话框的构造函数中添加了这一行

 public AnimationDialog(Activity a, int drawable) {
    super(a);
    // TODO Auto-generated constructor stub
    this.c = a;
    this.mDrawable = drawable;
    this.getWindow().getAttributes().windowAnimations = R.style.DialogSlideAnim;
}
Run Code Online (Sandbox Code Playgroud)

以下行是我为实现动画而添加的内容,如上所示

this.getWindow().getAttributes().windowAnimations = R.style.DialogSlideAnim;

但没有任何反应,我的对话框显示为默认情况

这是我的样式文件供参考

 <style name="DialogAnimation">
    <item name="android:windowEnterAnimation">@anim/slide_down_animation</item>
    <item name="android:windowExitAnimation">@anim/slide_up_animation</item>
</style>

<!-- Animation for dialog box -->
<style name="DialogSlideAnim" parent="@android:style/Theme.Dialog">
    <item name="android:windowAnimationStyle">@style/DialogAnimation</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但是我的动画仍然无法正常工作,我做错了什么,?请告诉我我怎样才能做到这一点?如何为我的自定义对话框设置动画。

编辑

这是我的下滑动画

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromYDelta="0%p"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toYDelta="100%p" />

</set>
Run Code Online (Sandbox Code Playgroud)

这是我的向上滑动动画

 <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromYDelta="100%"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toXDelta="0" />
</set>
Run Code Online (Sandbox Code Playgroud)

Bar*_*ski 7

尝试这个:

slide_down_animation.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromYDelta="-100%p"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toYDelta="0%p" />
</set>
Run Code Online (Sandbox Code Playgroud)

slide_up_animation.xml

<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="@android:integer/config_mediumAnimTime"
        android:fromYDelta="0%p"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toYDelta="-100%p" />
</set>
Run Code Online (Sandbox Code Playgroud)

编辑:

除此之外,您还可以尝试以这种方式设置样式:

getWindow().setWindowAnimations(R.style.DialogAnimation);
Run Code Online (Sandbox Code Playgroud)

不是 R.style.DialogSlideAnim