【问题标题】:Change animation in runtime在运行时更改动画
【发布时间】:2012-07-08 21:47:29
【问题描述】:

我想完成简单的任务 - 在对话框关闭之前,我想根据我的逻辑设置不同的关闭动画(getWindow().getAttributes().windowAnimations = ...)。例如,我在对话框上有 2 个按钮,如果按下第一个,我想向左滑动,如果按下第二个,我想向右滑动。我已经为 android:windowExitAnimation 和 android:windowEnterAnimation 创建了带有一些动画的样式文件,如果在自定义对话框构造函数中传递它们,它们就可以工作。但是我不能在代码中覆盖 windowAnimations,因为我需要不同的动画,所以不能使用构造函数方法。怎么做?为什么这段代码不起作用?

        // close button
        _button_close = (ImageButton)findViewById(R.id.buttonClose);

        if (_button_close != null) 
        {
            _button_close.setOnClickListener(
                new Button.OnClickListener() 
                {  
                    public void onClick(View v)
                    {
                        // set animation
                        getWindow().getAttributes().windowAnimations = R.style.DialogSlideOutLeft;

                        // close form
                        dismiss();
                    }
                }
            );
        }   

【问题讨论】:

    标签: android


    【解决方案1】:

    我也遇到了同样的问题。 这是我的解决方案:`

            alertCheckIn = new Dialog(this);
            alertCheckIn.setTitle("Check-In");
            alertCheckIn.setContentView(textEntryView); //my custom dialog layout
    
            lpDialog = alertCheckIn.getWindow().getAttributes();
            lpDialog.windowAnimations = R.style.FadeInDropOutDialogAnimation;
            alertCheckIn.getWindow().setAttributes(lpDialog);
    
            alertCheckIn.show();
    

    `

    然后当我想切换动画时: `

            lpDialog.windowAnimations = R.style.FadeInSlideLeftOutDialogAnimation;
            alertCheckIn.getWindow().setAttributes(lpDialog);
            alertCheckIn.cancel();`
    

    何时:

    private WindowManager.LayoutParams lpDialog;
    

    【讨论】:

    • 对我没有任何影响
    猜你喜欢
    • 1970-01-01
    • 2014-09-25
    • 2022-11-30
    • 1970-01-01
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多