如何在离开活动时(之前)启动布局动画

发布于 2024-12-13 20:02:24 字数 687 浏览 6 评论 0原文

我的活动中有一个 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() 以查看动画是否开始,但它没有开始。

有人有类似问题吗?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

哑剧 2024-12-20 20:02:24

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

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

帅哥哥的热头脑 2024-12-20 20:02:24

试试这个。它可能会帮助你:

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

}

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

}
温馨耳语 2024-12-20 20:02:24

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文