我正在编写我的徽标活动和我的主要活动之间的过渡效果,但我有一个问题,即在消失之前,活动转移到顶部:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >
<alpha
android:duration="2000"
android:fromAlpha="0.0"
android:toAlpha="1.0" >
</alpha>
</set>
Run Code Online (Sandbox Code Playgroud)
我怎么能改进这个代码才能获得消失效果呢?
我有一个带有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;
}
});
}
Run Code Online (Sandbox Code Playgroud)
是的我正在为Lollipop优化它,对于Lollipop之前的设备,我是jsut使用overridePendingTransitions,它工作正常.我的问题只在Lollipop设备上.
顺便说一句,我的Enter和Exit转换都是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>
Run Code Online (Sandbox Code Playgroud) 我使用以下元素为我的应用程序定义了一个基本样式:
<item name="android:windowBackground">@color/window_background</item>
Run Code Online (Sandbox Code Playgroud)
这为我的所有活动设置了背景颜色,直到我在Android 6上测试我的应用程序,其中所有背景都是白色的.在运行前棉花糖的设备上,背景仍然是color/window_background.
任何人都知道如何在Android 6上完成这项工作(或者为什么它不起作用)?
使用更多信息进行修改:我的目标是API 22,我没有更改以前版本的任何内容或升级API,只需在Android 6上运行即可更改背景.