我有一个DrawerLayout的活动,但每当它打开有一个像一个瞬间的延迟,其中屏幕是白色的,然后我的屏幕上绘制。
这发生在过渡结束后。因此,那种看起来像屏幕动画过渡跳跃。
我试图把这个在我的OnCreate结合与奶油刀意见后,却什么也没做。
如果(Build.VERSION.SDK_INT> = Build.VERSION_ codeS.LOLLIPOP){ postponeEnterTransition(); drawerLayout.getViewTreeObserver()。插件preDrawListener(新ViewTreeObserver.On preDrawListener(){ @TargetApi(Build.VERSION_ codeS.LOLLIPOP) 在preDraw公共布尔(){ drawerLayout.getViewTreeObserver()removeOn preDrawListener(本)。 startPostponedEnterTransition(); 返回true; } }); }
是的,我优化它棒棒糖,和我仅仅指刚使用 overridePendingTransitions
pre-棒棒糖设备和它工作正常。我的问题是只有棒棒堂的设备。
顺便说一句,我的进入和退出的转换都是 fade_in_out
在XML定义中指定风格
<样式名称=AppTheme父=Theme.AppCompat.Light> <项目名称=colorAccent> @色/粉红色和LT; /项目> <项目名称=windowActionBar>假LT; /项目> <项目名称=windowNoTitle>真< /项目> <项目名称=机器人:windowDrawsSystemBarBackgrounds>真< /项目> <项目名称=机器人:windowActivityTransitions>真< /项目> <项目名称=机器人:windowContentTransitions>真< /项目> <! - 规定进入和退出的转换 - > < - 选项有:爆炸,幻灯片,褪色 - > <项目名称=机器人:windowEnterTransition> @过渡/ fade_in_out_transition< /项目> <项目名称=机器人:windowExitTransition> @过渡/ fade_in_out_transition< /项目> &所述;! - 指定共享单元跃迁 - > <项目名称=机器人:windowSharedElementEnterTransition> @过渡/ change_clip_bounds< /项目> <项目名称=机器人:windowSharedElementExitTransition> @过渡/ change_clip_bounds< /项目> <项目名称=机器人:windowSoftInputMode> stateAlwaysHidden | adjustResize< /项目>< /风格>
解决方案
我终于找到了解决这个。我不知道为什么,或者它是如何工作了,但我只知道,它删除了动画的延迟。我加了一个处理程序中的的OnCreate
将运行建立,即增加初始片段眼帘,300毫秒后的其他语句活动的
处理程序mHandler =新的处理程序();mHandler.postDelayed(新的Runnable(){ @覆盖 公共无效的run(){ switchFragment(); }},300);
I have an activity with a DrawerLayout but whenever it opens there is a delay like a split-second where the screen is white then my screen is drawn.
This happens after the Transition finishes. So it sort of looks like the screen animation transition is jumping.
I tried putting this on my OnCreate after binding the views with ButterKnife but it did nothing.
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;
}
});
}
Yes I am optimizing it for Lollipop, and for pre-Lollipop devices I am jsut using overridePendingTransitions
and it works fine. My problem is only on Lollipop devices.
Btw, my Enter and Exit transitions are both fade_in_out
defined in xml and specified in 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>
解决方案
I finally found a solution to this. I don't know why or how it worked out but I just know that it removed the delay in the animations. I added a handler in the OnCreate
of the activity that would run the other statements for setting up, i.e. adding the initial fragment into view, after 300ms
Handler mHandler = new Handler();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
switchFragment();
}
}, 300);
上一篇:其中Eclipse IDE的使用为Android开发?Eclipse、IDE、Android
下一篇:java.lang.IllegalArgumentException异常:坏类:类java.util.GregorianCalendar中的异常、lang、java、IllegalArgumentEx