[英]Prevent view to be in front during animation
I have a button that shows or hides a view. 我有一个显示或隐藏视图的按钮。 When button get pressed the view is added to layout and a translate animation begins.
当按下按钮时,视图将添加到布局中,然后开始翻译动画。 Second button press will remove the view from the layout.
第二次按下按钮将从布局中删除该视图。 I user
addView(view, 0)
to make sure the view is behind all other views. 我使用
addView(view, 0)
来确保该视图位于所有其他视图的后面。 It works generally fine. 它通常工作正常。
The problem occurs when the view is shown and I press the button twice very fast (sort of double click). 显示视图时出现问题,我非常快速地按了两次按钮(有点双击)。 In that case the view jumps to front during the animation.
在这种情况下,动画过程中视图会跳到最前面。
How can I prevent this? 我该如何预防?
Just disable( setEnabled(false)
) the button and enable it in AnimationListener.onAniationEnd()
. 只需禁用(
setEnabled(false)
)按钮并在AnimationListener.onAniationEnd()
启用它即可。
UPD : ok, that's the code, which illustrates my idea: UPD :好的,这就是代码,它说明了我的想法:
final Button btn = (Button) findViewById(R.id.myButton);
View view = (View) findViewById(R.id.myView);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
btn.setEnabled(false);
// animation here
addView(view, 0);
}
});
// somewhere else
final Button btn = (Button) findViewById(R.id.myButton);
btn.setEnabled(true);
removeView(view);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.