【问题标题】:Keeping background the same when sliding activities with overridependingtransition()使用 overridependingtransition() 滑动活动时保持背景相同
【发布时间】:2014-01-09 12:42:07
【问题描述】:

我正在使用此代码从一个活动滑到另一个活动。

overridePendingTransition(R.anim.enter_from_right, R.anim.exit_out_left);

当背景是纯色时,这很有效。但是,我的背景不是纯色。下面是我的背景。

因此,当此背景从右向左滑动时,您会注意到过渡。我希望唯一需要注意的是 Buttons、TextViews 等正在移动。我怎样才能做到这一点?

编辑

基于 Matt 的 cmets(另一个 Matt,不是我),我创建了一个 Splash Activity 并将其背景设置为云背景。然后我从所有其他活动中删除了云背景。当 SplashScreen 转换到 MainMenu 类时,显示如下:

所以基本上我看到了所有应用程序所在的模拟器的主屏幕。下面是我的新AndroidManifest.xml

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity 
        android:name=".SplashScreen"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action 
                android:name="android.intent.action.MAIN" />
            <category 
                android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:label="@string/app_name"
        android:name=".MainMenu"
        android:screenOrientation="portrait" 
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />
    <activity
        android:label="@string/app_name"
        android:name=".Levels"
        android:screenOrientation="portrait" 
        android:theme="@android:style/Theme.Translucent.NoTitleBar" />

我将此添加到我的styles.xml

<style name="Theme.Transparent" parent="android:Theme">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:backgroundDimEnabled">false</item>
</style>

编辑#2

我正在慢慢进步。现在 SplashScreen 启动,然后完美地过渡到 MainActivity。到其他屏幕的转换,例如当我单击播放按钮时,还不是很正确。它们在不改变背景的情况下进行转换,但之前的透明活动保留在那里,并且所有透明活动开始相互堆叠。有没有办法在启动新意图/活动时“关闭”透明活动,以免它们重叠和堆叠?

【问题讨论】:

    标签: java android animation slide


    【解决方案1】:

    我的第一个想法是使用该图像(可能是一个活动)在背景中保留一些东西,然后将活动设置为使用主题 @style/Theme.Transparent 滑过它

    【讨论】:

    • 我要出去度周末,几天内无法测试。届时将报告。
    • 我不确定如何按照您的建议进行操作。如果可以的话,你能给我提供更多的东西吗?否则,我仍然需要帮助。
    • 您是否将透明主题应用于您的活动?申请后你能看到他们背后不是黑色的东西吗?一旦你到达那里,你会想要创建一个类似“SplashActivity”的东西,作为你的背景在启动时启动。
    • 太棒了——看起来不错。现在创建一个仅包含一个全屏 ImageView(您的背景)的 Activity 并在您启动主 Activity 之前启动它...即使在您启动主 Activity 之后,ImageView Activity 会保持不变吗?您可能需要执行诸如 overridePendingTransitions() 之类的操作以确保它不会滑出,我不确定...
    • 请参阅我的开篇文章的编辑。感谢您耐心等待并帮助我度过难关!
    猜你喜欢
    • 2014-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多