1

我的活动中有一个 LinearLayout 视图。

当我按下后退按钮时,我希望 LinearLayout 的孩子滑出。

我有以下不做任何事情的代码:

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();     
}

我已经注释掉了 super.OnBackPressed() 以查看动画是否开始,并且它没有开始。

有类似问题的人吗?

4

3 回答 3

0

我认为您可能会在动画完成之前退出活动。尝试实现动画监听器

于 2012-09-16T21:06:28.607 回答
0

检查是否在 onBackPressed 中调用了 SlideOut() - 我猜你的背压正在其他地方处理 - 可能是通过虚拟键盘

于 2011-11-06T14:44:09.790 回答
0

试试这个。它可以帮助你:

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);

}

你可以在这里更改代码吗:

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);

}
于 2011-11-06T14:47:13.160 回答