3

Hi i am developing an app where i'm using shared element transition to animate enter and exit transitions on login and register activity animating one imageview and two textviews but my problem is that views are not animated at all instead when i click on register button the register activity blinks twice and no animation occurs and moreover the image in register activity losses its shape so i dont know where i'm going wrong becaues i have given same transition names in both the activites still the problem exists so i would appreciate some help. Here is my 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>

my login activity

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);

    }
Hardik Vasani
  • 876
  • 1
  • 8
  • 14
john
  • 140
  • 1
  • 16

4 Answers4

1

This is working in my code.

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>
Hardik Vasani
  • 876
  • 1
  • 8
  • 14
  • when i make new project with simple layout transition works but with complex layout it doesnt work at all that is why i'm confused.. – john May 08 '18 at 12:05
  • @john if this line is present in `manifest.xml` file `android:hardwareAccelerated="true"` remove this line from application tag. – Hardik Vasani May 08 '18 at 12:31
  • did thatstill no use. – john May 08 '18 at 12:37
  • i have a layerlist which losses its shape while animating what could be the reason.. – john May 08 '18 at 12:38
  • and the second issue is that now my custom layerlist is losing its shape aftergiving transition name – john May 08 '18 at 12:44
1

try this one.

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();
            }
Hardik Vasani
  • 876
  • 1
  • 8
  • 14
  • nope still the same.. but thanks for your time and patience – john May 08 '18 at 12:54
  • but can you help me the layer list it is actually losing its shape while trying to animate – john May 08 '18 at 12:59
  • [refer this one hope it will help you.](https://stackoverflow.com/questions/37491282/multiple-shared-elements) – Hardik Vasani May 08 '18 at 13:01
  • No actually i wanted to ask you about the layerlist which has custom shape but the custom shape losses its width in second activity – john May 08 '18 at 13:04
  • @john [please check this one](https://github.com/wasabeef/awesome-android-ui/blob/master/pages/Animation.md) – Hardik Vasani May 08 '18 at 13:08
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/170619/discussion-between-hardik-vasani-and-john). – Hardik Vasani May 08 '18 at 13:21
0

Have you tried using these in your style theme?

    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowActivityTransitions">true</item>
Zach Bublil
  • 857
  • 10
  • 28
0

I see you finish the current activity after start new one with transition. The enter and exit transition is lost if you finish that way.

Try to keep the LoginActivity to see if it works

Tam Huynh
  • 2,026
  • 1
  • 16
  • 20