1

I have a LinearLayout View in my activity.

When I press back button I want LinearLayout's children to slide out.

I have the following code which doesn't do anything:

private void SlideOut()
{
    LayoutAnimationController controller = AnimationUtils.loadLayoutAnimation(this, R.anim.layout_animation_row_slide_out);
    Animation animation=controller.getAnimation();
    animation.setFillAfter(true);
    LinearLayout menuLayout =((LinearLayout)findViewById(R.id.menuLayout));
    menuLayout.setLayoutAnimation(controller);
    menuLayout.startLayoutAnimation();
}

@Override
public void onBackPressed(){
    //super.onBackPressed();
    SlideOut();     
}

I have commented out super.OnBackPressed() to see if the animation starts, and it don't start.

Somebody with similar problems ?

Ionica
  • 139
  • 3
  • 13

3 Answers3

0

I think you might be exiting the activity before animation is finished. Try implementing Animation Listener

urSus
  • 12,492
  • 12
  • 69
  • 89
0

check if SlideOut() is called in onBackPressed - i'm guessing your back press is being handled elsewhere - possibly by the virtual keyboard

josephus
  • 8,284
  • 1
  • 37
  • 57
0

try this.it may help you:

public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub

    if(keyCode==KeyEvent.KEYCODE_BACK){
    SlideOut();
    return true;
    }else{
        return false;
    }

    //return super.onKeyDown(keyCode, event);

}

can u just change the code here here :

private void SlideOut()
{
    Animation controller = AnimationUtils.loadLayoutAnimation(this, R.anim.layout_animation_row_slide_out);
   // Animation animation=controller.getAnimation();
    animation.setFillAfter(true);
    LinearLayout menuLayout =((LinearLayout)findViewById(R.id.menuLayout));
    menuLayout.startAnimation(controller);

}
Android Killer
  • 18,174
  • 13
  • 67
  • 90