使用共享元素转换后,活动才会闪烁

时间:2018-05-08 10:45:23

标签: java android user-interface animation android-transitions

嗨,我正在开发一个应用程序,我使用共享元素转换动画进入和退出转换登录和注册活动动画一个imageview和两个textview但我的问题是视图根本没有动画,而是当我点击注册按钮,注册活动闪烁两次,没有动画发生,而且注册活动中的图像失去了它的形状,所以我不知道我哪里出错了因为我在两个活动中都给出了相同的转换名称仍然存在问题所以我会感激一些帮助。 这是我的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);

    }

4 个答案:

答案 0 :(得分:1)

这在我的代码中有效。

styles.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>

styles.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>

答案 1 :(得分:1)

尝试这个。

View sharedView = splashLogo;
            String transitionName = getString(R.string.splash_logo_animate);
            if (Build.VERSION.SDK_INT >= 21) {
                ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(SplashscreenActivity.this, sharedView, transitionName);
                startActivity(i, options.toBundle());
                finishAfterTransition();
            }
            else {
                ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(SplashscreenActivity.this, sharedView, transitionName);
                ActivityCompat.startActivity(getApplicationContext(), i, options.toBundle());
                finish();
            }

答案 2 :(得分:0)

您是否尝试在风格主题中使用这些?

    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowActivityTransitions">true</item>

答案 3 :(得分:0)

我看到你在启动过渡后的新活动后完成当前活动。如果你这样完成,进入和退出转换就会丢失。

尝试保持LoginActivity以确定其是否有效