8

I have two buttons.When first button is pressed i am translating my layout layout to top and from the top of the screen another layout will come.But my issue is when came back to first layout the click events of the second layout still get fired at its previous position.So what is the Solution of it?I found a lot here on SO as well as on Google but still cannot get the right solution yet.So Please someone help me for my this issue.Thanks in Advance.

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);
                    }
                });
            }
        });
Sudhasri
  • 1,264
  • 16
  • 19
Biginner
  • 243
  • 1
  • 2
  • 15
  • means r u expanding 1 layout and collapsing other layout? – TheFlash Jun 12 '13 at 13:33
  • do you want to do this with the help of expand and collapse animation? – TheFlash Jun 13 '13 at 04:25
  • @Pratik : well just want to do one layout is going up.after the layout touches the top of the phone screen i want to show another layout coming from the top of the phone Screen.I have done it with the help of translate animation but my problem is after translating i am able to click events of the second layout still get fired at its previous position.what is the solution of it? – Biginner Jun 13 '13 at 04:32
  • i want to see your XML can you please post it?. – TheFlash Jun 13 '13 at 04:57
  • @Pratik : i have done with java code not using XML. – Biginner Jun 13 '13 at 04:59
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/31700/discussion-between-user1317-and-pratik) – Biginner Jun 13 '13 at 05:10
  • i m sure it will useful to u.try and let me know. – TheFlash Jun 13 '13 at 06:05
  • @Pratik : why you delete your answer? – Biginner Jun 13 '13 at 09:40
  • i thought it did not work for you.That's y i have deleted. – TheFlash Jun 13 '13 at 10:35
  • @Pratik : i tried it but layouts are not moving – Biginner Jun 13 '13 at 10:59
  • dude not working??How r u passing the view? – TheFlash Jun 13 '13 at 11:06
  • @Pratik : like this..is it right? View_login = getLayoutInflater().inflate(R.layout.activity_login, null); layout_signup = (LinearLayout) findViewById(R.id.layout_signup); View_SignUp = getLayoutInflater().inflate( R.layout.include_layout_signup, null); collapse(View_login); expand(View_SignUp); – Biginner Jun 13 '13 at 11:28
  • yup it's write way..but i m surprised why it is not working. – TheFlash Jun 13 '13 at 11:31
  • first check to simple view i mean not inflated view.I have tested this animations and they r working. – TheFlash Jun 13 '13 at 11:32

1 Answers1

12

I think this is a bug with the old animator schemes (I beleive a pretty well known bug, involving fill after not working sometimes). 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 translationY. If you want to move in both directions, you need a translationX and translationY, and use an AnimatorSet to play simultaneously.

Check out this comment to this question. Using the old Animation API, apparently dispite fillAfter(true), the buttons click position remains the same. This confirms your issue. So just use the new API, and you should be in good shape.

Community
  • 1
  • 1
Jameo
  • 4,507
  • 8
  • 40
  • 66
  • I think this will help me to move my layout in X Co-Ordinate but if i want to move my layout to Y Co-Ordinate then what should i have to do? I think for that i will not help me. am I Right? – Biginner Jun 14 '13 at 04:37
  • ObjectAnimator oa = ObjectAnimator.ofFloat(view, "translationY", 0, 5f); would do it – Jameo Jun 14 '13 at 12:52
  • Check out my edit to the question. I found another question that had the exact same issue. My solution should solve, FYI – Jameo Jun 14 '13 at 13:09