开发者

Change animation in runtime

I want to achieve simple tasks - before dialog is dismissed, I want to set different close animation depending on my logic (getWindow().getAttributes().windowAnimations = ...). For examle, I have 2 buttons on dialog and i want to slide left if first is pressed, slide right if second is pressed. I have created style file with some animations for android:windowExitAnimation and android:windowEnterAnimation and they work if passed in custom dialog constructor. But I cant override windowAnimations within the code as constructor approach can no be used as I need dif开发者_StackOverflow社区ferent animations. How can it be done and why this code is not working?

        // 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();
                    }
                }
            );
        }   


I have had same problem. Here is my solution:`

        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();

`

and then when i want to switch animation: `

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

when:

private WindowManager.LayoutParams lpDialog;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜