动画片段和背面叠 [英] Animating fragments and the back stack

查看:101
本文介绍了动画片段和背面叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用或了解如何喀啦有麻烦 FragmentTransactions断背栈处理自定义 动画。具体而言,我希望它叫出的动画,但 它似乎没有。

I am having trouble using or understanding how popping FragmentTransactions off of the back stack handles the custom animations. Specifically, I expect it to call the "out" animation, but it doesn't seem to.

我有一个简单的方法来处理片段交易 (FragmentTransaction),我添加一个片段,并应用自定义 过渡,这样它会淡入/淡出。我也在这 背面叠层以使用户可以撤消该交易的 后退按钮,从根本上导航到状态的片段之前 溶液。

I have a simple method to handle a fragment transaction (FragmentTransaction) where I add a fragment and apply a custom transition so that it will fade-in/fade-out. I am also adding this to the back stack so that the user can undo that transaction with the back button, essentially navigating to the state before the fragment was added.

protected void changeFragment() { 
    FragmentTransaction ft = fm.beginTransaction(); 
    ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out); 
    ft.add(R.id.fragment_container, new TestFragment()); 
    ft.addToBackStack(null); 
    ft.commit(); 
} 

一切的伟大工程向前发展,但是,当用户点击 后退按钮,过渡动画不逆转。我的预期 是该片段得到了取出时,它会使用淡出 动画。相反,它似乎弹出(无动画),然后 容器似乎淡入。我不知道这是什么 正在发生的事情,但片段绝对不会淡出。

Everything works great moving forward, but when the user clicks the back button, the transition animations do not reverse. What I expected was that when the fragment got removed, it would use the fade out animation. Instead it seems to pop out (without animation) and then the container seems to fade in. I'm not sure that this is exactly what is happening, but the fragment is definitely not fading out.

我的应用程序使用兼容性库添加片段支持, 但我认为这是适用于蜂窝(Android的11)也是如此。 有谁知道,如果我只是在这里做得不对,或者如果我 只是期望太高了?理想情况下,我想动画 片段类似于Gmail的(对Xoom的)怎么做的问候 向前移动点击的消息,然后返回通过使用回 按钮。 preferably不必重写后退按钮 功能和我自己的片段状态跟不上,因为我可以 有几个交易,我想背出来,我 重新发明轮子不是一个球迷。

My application uses the compatibility library to add fragment support, but I assume this to be applicable to Honeycomb (android-11) as well. Does anyone know if I am just doing something wrong here or if I am just expecting too much? Ideally, I would like to animate the fragments similarly to how Gmail (on the Xoom) does in regards to moving forward by clicking a message and then back by using the back button. Preferably not having to override the back button functionality and keep up with my own fragment state since I could have several "transactions" that I would want to back out of and I am not a fan of re-inventing wheels.

同时要求对Android开发组:<一href="http://groups.google.com/group/android-developers/browse_thread/thread/1136a3a70fa0b6e9">http://groups.google.com/group/android-developers/browse_thread/thread/1136a3a70fa0b6e9

Also asked on the Android Developers Group: http://groups.google.com/group/android-developers/browse_thread/thread/1136a3a70fa0b6e9

推荐答案

在修正了3.2版本通过添加以下新​​的API:

The bug was fixed in the 3.2 release with the addition of the following new api:

<一个href="http://developer.android.com/reference/android/app/FragmentTransaction.html#setCustomAnimations%28int,%20int,%20int,%20int%29">http://developer.android.com/reference/android/app/FragmentTransaction.html#setCustomAnimations(int, INT,INT,INT)

这是应当注意,它尚未后移植到兼容性库(如上文中的错误报告)。

It's to be noted that it has not yet been back-ported to the compatibility library (as mentioned in the bug report).

这篇关于动画片段和背面叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆