I was implementing material design for my app. I saw that it is possible to make transitions between activities just here: http://android-developers.blogspot.com.es/2014/10/implementing-material-design-in-your.html
So i tried to follow what "Authentic motion" section says:
ActivityMain.java
Intent intent = new Intent();
String transitionName = getString(R.string.transition_album_cover);
…
ActivityOptionsCompat options =
ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
albumCoverImageView, // The view which starts the transition
transitionName // The transitionName of the view we’re transitioning to
);
ActivityCompat.startActivity(activity, intent, options.toBundle());
activity_main.xml
<ImageView
…
android:transitionName="@string/transition_album_cover" />
activity_details.xml
<ImageView
…
android:transitionName="@string/transition_album_cover" />
However, this seems to make the default android activity transition, and I see no animations.
Keep in mind that I called requestWindowFeature(Window.FEATURE_CONTENT_TRANSITIONS) as it says here http://developer.android.com/reference/android/support/v4/app/ActivityOptionsCompat.html#makeSceneTransitionAnimation(android.app.Activity, android.view.View, java.lang.String)
Also all this was tested with a Nexus4 API Level 19
Where is the problem?
Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.
You opened the new activity from another activity with startActivityForResult. In that case you can just call the finishActivity() function from your code and it'll take you back to the previous activity.
ActivityOptionsCompat.makeSceneTransitionAnimation
works only on api level >= 21.
From docs:
Some material design features like the material theme and custom activity transitions are only available on Android 5.0 (API level 21) and above. However, you can design your apps to make use of these features when running on devices that support material design and still be compatible with devices running previous releases of Android.
Here is it's definition:
public static ActivityOptionsCompat makeSceneTransitionAnimation(Activity activity,
View sharedElement, String sharedElementName) {
if (Build.VERSION.SDK_INT >= 21) {
return new ActivityOptionsCompat.ActivityOptionsImpl21(
ActivityOptionsCompat21.makeSceneTransitionAnimation(activity,
sharedElement, sharedElementName));
}
return new ActivityOptionsCompat();
}
So why does that method exist in support package?
It is done so in order to maintain backward compatibility with older versions (api level <=20). From maintaining compatibility docs:
// Check if we're running on Android 5.0 or higher
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Call some material design APIs here
} else {
// Implement this feature without material design
}
Activity Transitions are exclusive to Android 5.0. ActivityOptionsCompat. makeSceneTransitionAnimation
doesn't do anything if you're running 19 or below.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With