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. 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()
.
UPD : ok, that's the code, which illustrates my idea:
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.