我有一个带有 DrawerLayout 的活动,但每当它打开时,都会有一个延迟,就像屏幕变白然后绘制我的屏幕一样。
这发生在转换完成后。所以看起来屏幕动画过渡有点跳跃。
在将视图与 ButterKnife 绑定后,我尝试将其放在 OnCreate 上,但它什么也没做。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
postponeEnterTransition();
drawerLayout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public boolean onPreDraw() {
drawerLayout.getViewTreeObserver().removeOnPreDrawListener(this);
startPostponedEnterTransition();
return true;
}
});
}
是的,我正在针对 Lollipop 进行优化,对于我刚刚使用的 Pre-Lollipop 设备overridePendingTransitions
而且效果很好。我的问题仅出现在棒棒糖设备上。
顺便说一句,我的进入和退出转换都是fade_in_out
在 xml 中定义并在中指定styles
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorAccent">@color/pink</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowActivityTransitions">true</item>
<item name="android:windowContentTransitions">true</item>
<!-- specify enter and exit transitions -->
<!-- options are: explode, slide, fade -->
<item name="android:windowEnterTransition">@transition/fade_in_out_transition</item>
<item name="android:windowExitTransition">@transition/fade_in_out_transition</item>
<!-- specify shared element transitions -->
<item name="android:windowSharedElementEnterTransition">@transition/change_clip_bounds</item>
<item name="android:windowSharedElementExitTransition">@transition/change_clip_bounds</item>
<item name="android:windowSoftInputMode">stateAlwaysHidden|adjustResize</item>
</style>
我终于找到了解决这个问题的方法。我不知道为什么或如何解决,但我只知道它消除了动画中的延迟。我在中添加了一个处理程序OnCreate
将运行其他语句进行设置的活动,即将初始片段添加到视图中,300 毫秒后
Handler mHandler = new Handler();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
switchFragment();
}
}, 300);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)