我正在尝试应用自定义动画来显示和隐藏 aDialog
并遇到了某个问题。
AView
提供了两种动画方法.animate()
,我称之为“手动”动画和.startAnimation(Animation animation)
接收Animation
对象。
我通过调用访问对话框的视图alertDialog.getWindow().getDecorView()
并尝试使用它来设置动画,startAnimation
但这不起作用。只有当我使用该animate
功能时,我才能为其设置动画。
这是一个代码示例,据我所知,它应该返回相同的结果,但会重现我正在处理的问题:
AlertDialog dialog = AlertDialog.Builder(MainActivity.this).create(); // Create the dialog
View decorView = dialog.getWindow().getDecorView(); // Access the dialog's view
// The animation below works fine
decorView.animate().rotationXBy(45).setDuration(500).start(); // Animate it "manually"
// Create an animation instance
RotateAnimation scaling = new RotateAnimation(0, 45);
scaling.setDuration(500);
scaling.setFillAfter(true);
// This animation does NOT work
decorView.startAnimation(scaling);
我已经在其他视图中尝试了相同的代码并且它正常工作,所以我猜想破坏功能的对话框有一些特殊性吗?
我想知道我是否做错了什么,如果可能的话,我怎样才能实现我想要的?
我最终选择了其他方式而不是使用对话框,但是使用它们,您确实必须逐步手动创建动画,而不是使用平台提供的那些有用的类。
我认为这可能是与视图尚未准备好相关的一些问题Animation
,甚至在 a 中启动它,decorView.post(Runnable)
但获得了相同的结果。
如果其他人尝试这种方法(真的不要,创建自己的视图并正常动画它,你会遇到更糟糕的动画对话框的关闭问题)请注意动画对话框不是那么容易。也许寻找这样做的图书馆。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句