【发布时间】: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