Click Play when two layouts are animated

I have two buttons. When the first button is pressed, I translated the layout of the layout from above, and another layout came out from the top of the screen. But my problem is that when I returned to the first layout, the click events of the second layout are still being fired at the previous position. So what is it? I found a lot here, both on SO and Google, but still can't find the right solution. So please help me with this.,

TranslateAnimation tr1 = new TranslateAnimation(0, 0, 0, -1100); tr1.setDuration(1000); tr1.setFillAfter(true); layout_login.startAnimation(tr1); tr1.setAnimationListener(new AnimationListener() { public void onAnimationStart(Animation animation) { } public void onAnimationRepeat(Animation animation) { } public void onAnimationEnd(Animation animation) { layout_signup.setVisibility(View.VISIBLE); TranslateAnimation tr2 = new TranslateAnimation(0, 0, -1100, 0); tr2.setDuration(1000); tr2.setFillAfter(true); tr2.setInterpolator(MainActivity.this, android.R.anim.linear_interpolator); layout_signup.startAnimation(tr2); tr2.setAnimationListener(new AnimationListener() { public void onAnimationStart(Animation animation) { } public void onAnimationRepeat(Animation animation) { } public void onAnimationEnd(Animation animation) { home_activity_btn_login.setEnabled(true); } }); } }); 
+8
android android-layout
source share
1 answer

I think this is a mistake with the old animator schemes (I believe in a fairly well-known error, including filling after it didn't work). Try using ObjectAnimator instead

Here is an example

 ObjectAnimator oa = ObjectAnimator.ofFloat(view, "translationX", 0, 100f); oa.setDuration(1000); oa.start(); 

If you want to move in the Y direction, you can use the Y translation. If you want to move in both directions, you need X translation and Y translation, and at the same time use AnimatorSet.

Mark this comment on this question. Using the old animation API, apparently dispill fillAfter (true), the button position remains the same. This confirms your problem. So just use the new API and you should be in good shape.

+12
source share

All Articles