活动过渡之间,固定背景

时间:2018-07-05 07:58:10

标签: android activity-transition

我目前正在从事android项目。我有一个背景xml文件,该文件以样式设置为windowBackground。

我的问题是,在活动过渡之间,背景也会随着屏幕滑动。我希望固定背景,或者用其他方式冻结。这样一来,只有活动项上的组件才离开屏幕或滑动进入。

这是我的背景xml,

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@drawable/background_image" />
    <item
        android:drawable="@drawable/vavien_logo"
        android:gravity="bottom|right"
        android:bottom="@dimen/normal_margin"
        android:right="@dimen/xlarge_margin"/>
</layer-list>

这就是我在活动之间进行转换的方式,

Intent intent = new Intent(LoginActivity.this, MeetingsActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.enter_from_right, R.anim.exit_to_left);

为我的问题寻找解决方案。

2 个答案:

答案 0 :(得分:0)

我认为您可以按照自己的样式设置此<item name="android:windowAnimationStyle">@null</item>,它将禁用幻灯片动画。

答案 1 :(得分:0)

在您的styles.xml中声明样式

<resources>

    <style name="Theme.Background" parent="@style/Theme.AppCompat">
        <item name="android:windowBackground">@android:color/holo_blue_dark</item>
    </style>

</resources>

然后将此样式设置为manifest.xml中应用程序元素的主题

<application
        ...
        android:theme="@style/Theme.Background">

这样,所有活动将具有共同的背景,直到您在任何Activity元素下覆盖它为止。现在,当您在活动之间进行切换时,它将产生您想要的相同效果。

希望这会有所帮助。