gpt4 book ai didi

android - 删除幻灯片窗口转换在启动时创建的白屏

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:20:37 26 4
gpt4 key购买 nike

我正在使用黑色背景的 Activity 。同样的 Activity 也有一个工具栏和一个 DrawerLayout。这个白色屏幕使外观不一致。

当打开 Activity 时幻灯片转换速度非常慢时,它会变得更加明显。

有什么办法可以去掉吗?

在第二个 Activity 上设置进入转换的代码:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = activity.getWindow();

Slide slide = new Slide();
slide.setSlideEdge(Gravity.RIGHT);
slide.excludeTarget(android.R.id.statusBarBackground, true);
slide.excludeTarget(android.R.id.navigationBarBackground, true);
window.setEnterTransition(slide);
window.setExitTransition(slide);
}

我的风格

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowActivityTransitions">true</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">false</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowSoftInputMode">stateAlwaysHidden|adjustResize</item>
</style>

最佳答案

如何修复启动 Activity 的幻灯片过渡期间的白屏:

karaokyos answer 使用了 pre Lollipop Activity 过渡。这些转换针对整个 Activity 屏幕,不提供在转换期间排除部分屏幕的功能。

John Ernest Guadalupe 方法利用了 Lollipop 中引入的转换( Activity 和 fragment 转换)。观察到的“白屏”是窗口背景,在过渡期间逐渐淡入(more info about Activity & Fragment Transitions )。我想您是在布局的 Root View 中设置 Activity 的“黑色背景”?将窗口背景设置为黑色应该可以解决您的问题。

以编程方式:

window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));

主题:

<item name="android:windowBackground">@android:color/black</item>

这是最终的过渡。

Resulting Transition

编辑:如何提供 required调用 Activity 的滑出(左)过渡

第一个 Activity :

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
Slide slide = new Slide();
slide.setInterpolator(new LinearInterpolator());
slide.setSlideEdge(Gravity.LEFT);
slide.excludeTarget(android.R.id.statusBarBackground, true);
slide.excludeTarget(android.R.id.navigationBarBackground, true);
window.setExitTransition(slide); // The Transition to use to move Views out of the scene when calling a new Activity.
window.setReenterTransition(slide); // The Transition to use to move Views into the scene when reentering from a previously-started Activity.
window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
}

第二个 Activity :

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
Slide slide = new Slide();
slide.setInterpolator(new LinearInterpolator());
slide.setSlideEdge(Gravity.RIGHT);
slide.excludeTarget(android.R.id.statusBarBackground, true);
slide.excludeTarget(android.R.id.navigationBarBackground, true);
window.setEnterTransition(slide); // The Transition to use to move Views into the initial Scene.
window.setReturnTransition(slide); // The Transition to use to move Views out of the Scene when the Window is preparing to close.
window.setBackgroundDrawable(new ColorDrawable(Color.BLACK));
}

您可以尝试不同的插值器来改变过渡的速度。

使用 LinearInterpolator 的结果转换:

Resulting transition

如果你想消除第一个 Activity 的滑出和第二个 Activity 的滑入之间的间隙,你可以设置:

<item name="android:windowAllowEnterTransitionOverlap">true</item>

如何调试转换:

It can become a lot more apparent when you set a very slow duration to the Slide transition when opening an activity.

为了(视觉上)调试过渡,在开发设置中有 3 个选项(“窗口动画比例”、“过渡动画比例”、“动画持续时间比例”)以乘以所有过渡/动画的持续时间。

关于android - 删除幻灯片窗口转换在启动时创建的白屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33561523/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com