Reputation: 150
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);
}
Upvotes: 3
Views: 1827
Reputation: 1
For smooth transition, follow these two steps. Create image_transform.xml file in res/transition folder
<?xml version="1.0" encoding="utf-8"?>
<transitionSet>
<changeImageTransform />
<changeBounds />
<changeClipBounds />
<changeTransform />
</transitionSet>
Write these 2 lines in your called activity after findViewById(android.R.id.content).setTransitionName("userPic");
getWindow().setSharedElementEnterTransition(TransitionInflater.from(this).inflateTransition(R.transition.image_transform));
getWindow().setSharedElementExitTransition(TransitionInflater.from(this).inflateTransition(R.transition.image_transform));
Upvotes: 0
Reputation: 2477
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
Upvotes: 0
Reputation: 876
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();
}
Upvotes: 1
Reputation: 876
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>
Upvotes: 1
Reputation: 867
Have you tried using these in your style theme?
<item name="android:windowContentTransitions">true</item>
<item name="android:windowActivityTransitions">true</item>
Upvotes: 0