有没有办法反转活动动画的 z 顺序?基本上,当您启动新活动时,它会被添加到后台堆栈,并且其窗口会添加到前一个活动的窗口上。有时稍后返回时,从后台堆栈获取的活动会在顶部活动下方显示其窗口。大多数时候这是完全有道理的,但我对这种行为有以下问题。
我有一个小部件,它指向应用程序结构深处的某个位置。因此,当用户单击操作栏中的向上按钮时,我必须手动创建返回堆栈。但后来我实际上用新意图调用 startActivity ,指向一个附加了后堆栈的新活动..这里我们讨论问题..该 actvity 实际上是从顶部开始动画的,而不是像往常一样从后堆栈弹出时动画标准方式。
you can see the flow on the following picture
这是我如何重新创建任务返回堆栈并将用户导航到父活动的代码片段。同样在下面,您可以看到动画的屏幕截图。基本上,顶部的窗口应该位于底部(它在应用程序层次结构中较高)。仅供参考,所有这些动画都是通过标准 XML 窗口动画完成的,并通过 overridePendingTransition 调用触发。我尝试修改这些动画中的 z 调整,但它似乎只影响一个特定动画中的各个图层。
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
NavUtils.navigateUpTo(this, upIntent);
} else {
TaskStackBuilder.create(this)
.addNextIntentWithParentStack(upIntent)
.startActivities();
}
老问题,但我也遇到过同样的问题。解决办法是添加属性android:zAdjustment="top"
or android:zAdjustment="bottom"
在我们的动画定义中。例子:
Nothing_background.xml
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:zAdjustment="bottom"
android:duration="400"
android:fromXDelta="0%p"
android:toXDelta="0%p" >
</translate>
fade_in_foreground.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:zAdjustment="top">
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="400" />
</set>
在触发转换的代码中:
Intent intent = new Intent(FromActivity.this, ToActivity.class);
Bundle animate = ActivityOptions.makeCustomAnimation(getApplicationContext(),
R.anim.nothing_background, R.anim.fade_in_foreground).toBundle();
startActivity(intent, animate);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)