如何在离开活动时(之前)启动布局动画
我的活动中有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查 onBackPressed 中是否调用了 SlideOut() - 我猜你的后按正在其他地方处理 - 可能是通过虚拟键盘
check if SlideOut() is called in onBackPressed - i'm guessing your back press is being handled elsewhere - possibly by the virtual keyboard
试试这个。它可能会帮助你:
你可以在这里更改代码吗:
try this.it may help you:
can u just change the code here here :
我认为您可能会在动画完成之前退出活动。尝试实现动画监听器
I think you might be exiting the activity before animation is finished. Try implementing Animation Listener