Android:Interpolator无法处理自定义对话框

时间:2018-03-05 03:39:13

标签: android animation

我已经从顶部创建了一个带有输入动画的对话框。 那样:

 @Override
protected void onCreate(Bundle savedInstanceState) {
...
    Window dialogWindow = getWindow();
    assert dialogWindow != null;
    WindowManager.LayoutParams lp = dialogWindow.getAttributes();
    DisplayMetrics dm = mContext.getResources().getDisplayMetrics();
    lp.width = dm.widthPixels;
    lp.height = DisplayUtil.dip2px(mContext, 300);
    dialogWindow.setAttributes(lp);
    dialogWindow.setGravity(Gravity.TOP);
    dialogWindow.setWindowAnimations(R.style.DropDown);
...
}

<style name="DropDown" mce_bogus="1" parent="android:Animation">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowEnterAnimation">@anim/dropdown_in</item>
    <item name="android:windowExitAnimation">@anim/dropdown_out</item>
</style>

动画没问题,但插补器不起作用。 这是我定义的“dropdown_in”动画

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
     android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:duration="1000"
        android:fromYDelta="-100%p"
        android:toYDelta="0" />
</set>

2 个答案:

答案 0 :(得分:0)

看来你正在将一个Activity变成一个Dialog。在这种情况下,与Activity的动画存在冲突。您可能希望改写Activity的动画。请使用overridePendingTransition(R.style.DropDown,R.style.DropDown)更新您的代码;

@Override
protected void onCreate(Bundle savedInstanceState) {
...

    overridePendingTransition(R.style.DropDown, R.style.DropDown);

    Window dialogWindow = getWindow();
    assert dialogWindow != null;
    WindowManager.LayoutParams lp = dialogWindow.getAttributes();
    DisplayMetrics dm = mContext.getResources().getDisplayMetrics();
    lp.width = dm.widthPixels;
    lp.height = DisplayUtil.dip2px(mContext, 300);
    dialogWindow.setAttributes(lp);
    dialogWindow.setGravity(Gravity.TOP);
    dialogWindow.setWindowAnimations(R.style.DropDown);
...
}

答案 1 :(得分:0)

这可能会晚了,但是可以帮助任何搜索它的人。

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"android:shareInterpolator="true"
>
    <translate
        android:duration="1000"
        android:fromYDelta="-100%p"
        android:toYDelta="0" />
</set>