0

Im currently doing a simple animated dropdown and I ran into a problem.

When I click the button, the view slides down and so does the button. The button is staying in the same spot (at the bottom of the view) which is good. However, the onClickListener for the button doesnt move down with it.

For example, if my button is at the top of the layout, I click it, it moves out 50, but the onClickListener is staying at the top.

Button click

public void onSlideViewButtonClick(View view) {
    if (isUp) {
        slideUp(myView);
        slideUpButton(myButton);
        myButton.setText("Slide down");
    } else {
        slideDown(myView);
        slideDownButton(myButton);
        myButton.setText("Slide up");
    }
    isUp = !isUp;
}

Animations for the buttons.

// slide the view from below itself to the current position
public void slideDownButton(View view){
    view.setVisibility(View.VISIBLE);
    TranslateAnimation animate = new TranslateAnimation(
            0,                 // fromXDelta
            0,                 // toXDelta
            0,  // fromYDelta
            view.getHeight());                // toYDelta
    animate.setDuration(500);
    animate.setFillAfter(true);
    view.startAnimation(animate);
}

// slide the view from its current position to below itself
public void slideUpButton(View view){
    TranslateAnimation animate = new TranslateAnimation(
            0,                 // fromXDelta
            0,                 // toXDelta
            view.getHeight(),                 // fromYDelta
            0); // toYDelta
    animate.setDuration(500);
    animate.setFillAfter(true);
    view.startAnimation(animate);
}

How can I have the onClick follow the button (if that makes sense)?

letsCode
  • 2,774
  • 1
  • 13
  • 37

0 Answers0