2

I am developing screen in which four buttons move horizontally from left to right and on each button click I have to open webView so can anyone suggest how to change button position so that proper on click event of button is detected .

I have read : animation actually does not moves the button but only its images. so what is proper way to add button.

I am new to stackoverflow and android animation so please suggest....

setContentView(R.layout.activity_main);
     ll = (LinearLayout) findViewById(R.id.topbar);
     animation = AnimationUtils.loadAnimation(this, R.anim.animation_right);
     animation.setRepeatCount(TranslateAnimation.INFINITE);
     animation.setRepeatMode(TranslateAnimation.RESTART);
     animation.setAnimationListener(new SlidingButtonAnimationListener());
     animation.setDuration(30000);
    ll.startAnimation(animation);
    button1=(Button)findViewById(R.id.button1);
    button2=(Button)findViewById(R.id.button2);
    button3=(Button)findViewById(R.id.button3);
    button4=(Button)findViewById(R.id.button4);
    button1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.d(TAG, "Button1 clicked");
        }
    });
    button2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.d(TAG, "Button2 clicked");
        }
    });
    button3.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.d(TAG, "Button3 clicked");
        }
    });
    button2.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Log.d(TAG, "Button4 clicked");
        }
    });
}
private class SlidingButtonAnimationListener implements AnimationListener {

    public void onAnimationEnd(Animation animation){

    }

    public void onAnimationRepeat(Animation animation){}

    public void onAnimationStart(Animation animation){}

}
manish
  • 23
  • 5

1 Answers1

0

You need to use Object Animator to move the objects. I found a StackOverFlow answer about your question. Here is the link. that should solve it.

Community
  • 1
  • 1
osayilgan
  • 5,873
  • 7
  • 47
  • 68
  • it works but can u suggest what is setFillAfter(true) equivalent in objectanimator for back to back animation. – manish Feb 13 '14 at 05:38
  • This is one of the good explanations of your question. [Here](http://stackoverflow.com/a/5888969/1080954) – osayilgan Feb 13 '14 at 09:13