首页 > 解决方案 > 活动在使用共享元素转换后闪烁

问题描述

嗨,我正在开发一个应用程序,在该应用程序中,我使用共享元素转换为登录时的进入和退出转换设置动画,并为一个图像视图和两个文本视图设置动画,但我的问题是,当我单击注册按钮时,视图根本没有动画注册活动闪烁两次,没有动画发生,而且注册活动中的图像失去了它的形状,所以我不知道我哪里出错了,因为我在两个活动中都给出了相同的过渡名称,但问题仍然存在,所以我会很感激一些帮助。这是我的styles.xml

<resources xmlns:tools="http://schemas.android.com/tools">

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowEnableSplitTouch">false</item>
        <item name="android:splitMotionEvents">false</item>

        <!-- Transition -->
        <item name="android:windowContentTransitions" tools:targetApi="21">true</item>
        <item name="android:windowEnterTransition" tools:targetApi="21">@android:transition/fade
        </item>
        <item name="android:windowExitTransition" tools:targetApi="21">@android:transition/fade
        </item>
        <item name="android:windowActivityTransitions">true</item>
        <item name="android:windowSharedElementEnterTransition" tools:targetApi="21">
            @android:transition/move
        </item>
        <item name="android:windowSharedElementExitTransition" tools:targetApi="21">
            @android:transition/move
        </item>
    </style>


</resources>

我的登录活动

public void gotoregister(View view) {
        Intent intent = new Intent(LoginActivity.this,RegisterActivity.class);
        Pair[] pairs  = new Pair[3];
        pairs[0] = new Pair<View,String>(text_login,getResources().getString(R.string.login_text_transition));
        pairs[1] = new Pair<View,String>(login_page_curve,getResources().getString(R.string.transition_name_signup));
        pairs[2] = new Pair<View,String>(register_text,getResources().getString(R.string.register_text_transition));
        ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation
                (LoginActivity.this,pairs);
        startActivity(intent,optionsCompat.toBundle());
        finish();
        //overridePendingTransition(R.anim.bottom_up,R.anim.bottom_down);

    }

标签: javaandroiduser-interfaceanimationandroid-transitions

解决方案


这在我的代码中有效。

样式.xml

<!-- Base application theme. -->
    s<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowDisablePreview">true</item>
    <item name="android:windowEnableSplitTouch">false</item>
    <item name="android:splitMotionEvents">false</item>
    <item name="android:windowAnimationStyle">@style/CustomActivityAnimation</item>
</style>

<style name="AppTheme.NoActionBarMain">
    <item name="windowActionBar">false</item>
    <item name="android:windowDisablePreview">true</item>
    <item name="windowNoTitle">true</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowEnableSplitTouch">false</item>
    <item name="android:splitMotionEvents">false</item>
    <item name="android:colorForeground">@color/foreground_material_light</item>
</style>

样式.xml(v21)

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowDrawsSystemBarBackgrounds">true</item>
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:windowEnableSplitTouch">false</item>
    <item name="android:splitMotionEvents">false</item>
</style>

推荐阅读