Shall not be reproduced without permission


1. Animation expansion of shared elements

Android shared element animation is a type of transitionanimation created after Android 5.0. The most common field used by developers is the transitionName and common code:

val transitionActivityOptions = ActivityOptions.makeSceneTransitionAnimation(this, Pair(view,transitionName))
startActivity(Intent(this,MainActivity::class.java), transitionActivityOptions.toBundle())
Copy the code

Second, the expansion of functions

Common shared element animations are: ChangeImageTransform, changeClipBounds, changeBounds, fade, etc., so in addition to that, we can actually add our own custom animations for shared elements, So this library adds ReColor and ReRadius for color RBG animations for text, and radius animations for rounded corners in layouts.

<transition class="XXXXXXX"/>
Copy the code

Add it to the transitionSet

Third, expand the renderings of the library

Four, the realization principle:

In onCaptureSharedElementSnapshot SharedElementCallback this method analysis of this method, we can extract to the original View of the various elements, including high wide, position, color, etc., and the results generated is Parcelable, Now that we have the answer, we can wrap the Parcelable ourselves. We need to extract the information from Activity1 into a class that inherits Parcelable and pass it to another page. We then process what we get in Activity2 in onCreateSnapshotView and onSharedElementStart. Concrete implementation access Github address: this extension library address

Quick use: Add a reference to the Jitpack in build.gradle in the root directory

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
        
Copy the code

In the module build.gradle, introduce:

Dependencies {implementation 'com. Making. ShowMeThe: the Transition: 1.0.0 release -'}Copy the code

Create the XML in the project’s Res/Transition:

<? The XML version = "1.0" encoding = "utf-8"? > <transitionSet android:duration="xxxx" xmlns:android="http://schemas.android.com/apk/res/android"> <transition class="com.show.element.transition.Recolor"/> <transition class="com.show.element.transition.ReRadius"/> </transitionSet>Copy the code

Need two of the animation to add setExtraShareElementCallBack Activity () method, the method for expanding method.