├── .gitignore ├── .idea ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── hcy │ │ └── huchengyang │ │ └── transitionnote │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── hcy │ │ │ └── huchengyang │ │ │ └── transitionnote │ │ │ ├── MainActivity.java │ │ │ ├── custom │ │ │ ├── ChangeColor.java │ │ │ └── ChangeSceneColor.java │ │ │ └── fragment │ │ │ ├── AutoTransitionFragment.java │ │ │ ├── ChangeBoundsFragment.java │ │ │ ├── ChangeClipBoundsFragment.java │ │ │ ├── ChangeImageTransformFragment.java │ │ │ ├── ChangeScrollFragment.java │ │ │ ├── ChangeTransformFragment.java │ │ │ ├── CustomTransitionWithSceneFragment.java │ │ │ ├── CustomTransitionWithoutSceneFragment.java │ │ │ ├── ExplodeFadeSlideFragment.java │ │ │ ├── MainFragment.java │ │ │ ├── PathMotionFragment.java │ │ │ ├── SceneFragment.java │ │ │ └── TransitionSetFragment.java │ └── res │ │ ├── drawable-nodpi │ │ └── photo.jpg │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── custom0.xml │ │ ├── custom1.xml │ │ ├── custom2.xml │ │ ├── fragment_auto_transition.xml │ │ ├── fragment_change_bounds.xml │ │ ├── fragment_change_clip_bounds.xml │ │ ├── fragment_change_image_transform.xml │ │ ├── fragment_change_scroll.xml │ │ ├── fragment_change_transform.xml │ │ ├── fragment_custom_transition_with_scene.xml │ │ ├── fragment_custom_transition_without_scene.xml │ │ ├── fragment_explode.xml │ │ ├── fragment_path_motion.xml │ │ ├── fragment_scene.xml │ │ ├── fragment_transition_set.xml │ │ ├── red_square.xml │ │ ├── scene0.xml │ │ └── scene1.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ ├── ic_launcher_foreground.png │ │ └── ic_launcher_round.png │ │ ├── transition │ │ └── transition.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── hcy │ └── huchengyang │ └── transitionnote │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | Android 36 | 37 | 38 | CorrectnessLintAndroid 39 | 40 | 41 | LintAndroid 42 | 43 | 44 | PerformanceLintAndroid 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 56 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## TransitionNote 2 | Android transition api demo 3 | ## Describe 4 | This demo is used to learn the Transition framework and commonly used apis,[Blog address](http://rkhcy.github.io/2017/09/21/TransitionNote/) 5 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion "26.0.1" 6 | defaultConfig { 7 | applicationId "com.hcy.huchengyang.transitionnote" 8 | minSdkVersion 21 9 | targetSdkVersion 26 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation 'com.android.support:appcompat-v7:26.1.0' 25 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 26 | testImplementation 'junit:junit:4.12' 27 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 28 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 29 | compile 'com.jakewharton:butterknife:8.8.1' 30 | annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' 31 | } 32 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/huchengyang/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/hcy/huchengyang/transitionnote/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.hcy.huchengyang.transitionnote", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | 7 | import com.hcy.huchengyang.transitionnote.fragment.CustomTransitionWithSceneFragment; 8 | import com.hcy.huchengyang.transitionnote.fragment.CustomTransitionWithoutSceneFragment; 9 | import com.hcy.huchengyang.transitionnote.fragment.AutoTransitionFragment; 10 | import com.hcy.huchengyang.transitionnote.fragment.ChangeBoundsFragment; 11 | import com.hcy.huchengyang.transitionnote.fragment.ChangeClipBoundsFragment; 12 | import com.hcy.huchengyang.transitionnote.fragment.ChangeImageTransformFragment; 13 | import com.hcy.huchengyang.transitionnote.fragment.ChangeScrollFragment; 14 | import com.hcy.huchengyang.transitionnote.fragment.ChangeTransformFragment; 15 | import com.hcy.huchengyang.transitionnote.fragment.ExplodeFadeSlideFragment; 16 | import com.hcy.huchengyang.transitionnote.fragment.MainFragment; 17 | import com.hcy.huchengyang.transitionnote.fragment.PathMotionFragment; 18 | import com.hcy.huchengyang.transitionnote.fragment.SceneFragment; 19 | import com.hcy.huchengyang.transitionnote.fragment.TransitionSetFragment; 20 | 21 | public class MainActivity extends AppCompatActivity implements MainFragment.OnListItemClickListener{ 22 | 23 | @Override 24 | protected void onCreate(Bundle savedInstanceState) { 25 | super.onCreate(savedInstanceState); 26 | setContentView(R.layout.activity_main); 27 | if (savedInstanceState == null) { 28 | MainFragment mainFragment = new MainFragment(); 29 | getSupportFragmentManager().beginTransaction() 30 | .add(R.id.content, mainFragment) 31 | .commit(); 32 | } 33 | } 34 | 35 | @Override 36 | public void onListItemClick(int position) { 37 | Fragment fragment = null; 38 | switch (position) { 39 | case 0: 40 | fragment = new AutoTransitionFragment(); 41 | break; 42 | case 1: 43 | fragment = new ChangeBoundsFragment(); 44 | break; 45 | case 2: 46 | fragment = new ChangeClipBoundsFragment(); 47 | break; 48 | case 3: 49 | fragment = new ChangeImageTransformFragment(); 50 | break; 51 | case 4: 52 | fragment = new ChangeScrollFragment(); 53 | break; 54 | case 5: 55 | fragment = new ChangeTransformFragment(); 56 | break; 57 | case 6: 58 | fragment = new ExplodeFadeSlideFragment(); 59 | break; 60 | case 7: 61 | fragment = new TransitionSetFragment(); 62 | break; 63 | case 8: 64 | fragment = new PathMotionFragment(); 65 | break; 66 | case 9: 67 | fragment = new CustomTransitionWithoutSceneFragment(); 68 | break; 69 | case 10: 70 | fragment = new SceneFragment(); 71 | break; 72 | case 11: 73 | fragment = new CustomTransitionWithSceneFragment(); 74 | break; 75 | default: 76 | break; 77 | } 78 | getSupportFragmentManager().beginTransaction() 79 | .replace(R.id.content, fragment) 80 | .addToBackStack(null) 81 | .commit(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/custom/ChangeColor.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.custom; 2 | 3 | /** 4 | * Created by huchengyang on 2017/9/19. 5 | */ 6 | 7 | import android.animation.Animator; 8 | import android.animation.ArgbEvaluator; 9 | import android.animation.ValueAnimator; 10 | import android.graphics.drawable.ColorDrawable; 11 | import android.graphics.drawable.Drawable; 12 | import android.support.annotation.NonNull; 13 | import android.support.annotation.Nullable; 14 | import android.transition.Transition; 15 | import android.transition.TransitionValues; 16 | import android.view.View; 17 | import android.view.ViewGroup; 18 | 19 | /** 20 | * A sample implementation of support {@link Transition}. 21 | */ 22 | public class ChangeColor extends Transition { 23 | 24 | /** Key to store a color value in TransitionValues object */ 25 | private static final String PROPNAME_BACKGROUND = "com.hcy.huchengyang.transitionnote:change_color:background"; 26 | 27 | /** 28 | * Convenience method: Add the background Drawable property value 29 | * to the TransitionsValues.value Map for a target. 30 | */ 31 | private void captureValues(TransitionValues transitionValues) { 32 | // Capture the property values of views for later use 33 | transitionValues.values.put(PROPNAME_BACKGROUND, ((ColorDrawable) transitionValues.view.getBackground()).getColor()); 34 | } 35 | 36 | @Override 37 | public void captureEndValues(@NonNull TransitionValues transitionValues) { 38 | if (transitionValues.view.getBackground() instanceof ColorDrawable) { 39 | captureValues(transitionValues); 40 | } 41 | } 42 | 43 | @Override 44 | public void captureStartValues(@NonNull TransitionValues transitionValues) { 45 | if (transitionValues.view.getBackground() instanceof ColorDrawable) { 46 | captureValues(transitionValues); 47 | } 48 | } 49 | 50 | // Create an animation for each target that is in both the starting and ending Scene. For each 51 | // pair of targets, if their background property value is a color (rather than a graphic), 52 | // create a ValueAnimator based on an ArgbEvaluator that interpolates between the starting and 53 | // ending color. Also create an update listener that sets the View background color for each 54 | // animation frame 55 | @Override 56 | public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { 57 | if (null == startValues || null == endValues) { 58 | return null; 59 | } 60 | final View view = endValues.view; 61 | int startBackground = (Integer) startValues.values.get(PROPNAME_BACKGROUND); 62 | int endBackground = (Integer) endValues.values.get(PROPNAME_BACKGROUND); 63 | 64 | if (startBackground != endBackground) { 65 | ValueAnimator animator = ValueAnimator.ofObject(new ArgbEvaluator(), 66 | startBackground, endBackground); 67 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 68 | @Override 69 | public void onAnimationUpdate(ValueAnimator animation) { 70 | Object value = animation.getAnimatedValue(); 71 | if (null != value) { 72 | view.setBackgroundColor((Integer) value); 73 | } 74 | } 75 | }); 76 | return animator; 77 | } 78 | return null; 79 | } 80 | 81 | @Override 82 | public String[] getTransitionProperties() { 83 | return new String[]{ 84 | PROPNAME_BACKGROUND 85 | }; 86 | 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/custom/ChangeSceneColor.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.custom; 2 | 3 | 4 | import android.animation.Animator; 5 | import android.animation.ArgbEvaluator; 6 | import android.animation.ValueAnimator; 7 | import android.graphics.drawable.ColorDrawable; 8 | import android.graphics.drawable.Drawable; 9 | import android.support.annotation.NonNull; 10 | import android.support.annotation.Nullable; 11 | import android.transition.Transition; 12 | import android.transition.TransitionValues; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | 16 | /** 17 | * A sample implementation of support {@link Transition}. 18 | */ 19 | public class ChangeSceneColor extends Transition { 20 | 21 | /** Key to store a color value in TransitionValues object */ 22 | private static final String PROPNAME_BACKGROUND = "transitionnote:change_color:background"; 23 | 24 | /** 25 | * Convenience method: Add the background Drawable property value 26 | * to the TransitionsValues.value Map for a target. 27 | */ 28 | private void captureValues(TransitionValues values) { 29 | // Capture the property values of views for later use 30 | values.values.put(PROPNAME_BACKGROUND, values.view.getBackground()); 31 | } 32 | 33 | @Override 34 | public void captureEndValues(@NonNull TransitionValues transitionValues) { 35 | captureValues(transitionValues); 36 | } 37 | 38 | @Override 39 | public void captureStartValues(@NonNull TransitionValues transitionValues) { 40 | captureValues(transitionValues); 41 | } 42 | 43 | // Create an animation for each target that is in both the starting and ending Scene. For each 44 | // pair of targets, if their background property value is a color (rather than a graphic), 45 | // create a ValueAnimator based on an ArgbEvaluator that interpolates between the starting and 46 | // ending color. Also create an update listener that sets the View background color for each 47 | // animation frame 48 | @Nullable 49 | @Override 50 | public Animator createAnimator(@NonNull ViewGroup sceneRoot, 51 | @Nullable TransitionValues startValues, 52 | @Nullable TransitionValues endValues) { 53 | // This transition can only be applied to views that are on both starting and ending scenes. 54 | if (null == startValues || null == endValues) { 55 | return null; 56 | } 57 | // Store a convenient reference to the target. Both the starting and ending layout have the 58 | // same target. 59 | final View view = endValues.view; 60 | // Store the object containing the background property for both the starting and ending 61 | // layouts. 62 | Drawable startBackground = (Drawable) startValues.values.get(PROPNAME_BACKGROUND); 63 | Drawable endBackground = (Drawable) endValues.values.get(PROPNAME_BACKGROUND); 64 | // This transition changes background colors for a target. It doesn't animate any other 65 | // background changes. If the property isn't a ColorDrawable, ignore the target. 66 | if (startBackground instanceof ColorDrawable && endBackground instanceof ColorDrawable) { 67 | ColorDrawable startColor = (ColorDrawable) startBackground; 68 | ColorDrawable endColor = (ColorDrawable) endBackground; 69 | // If the background color for the target in the starting and ending layouts is 70 | // different, create an animation. 71 | if (startColor.getColor() != endColor.getColor()) { 72 | // Create a new Animator object to apply to the targets as the transitions framework 73 | // changes from the starting to the ending layout. Use the class ValueAnimator, 74 | // which provides a timing pulse to change property values provided to it. The 75 | // animation runs on the UI thread. The Evaluator controls what type of 76 | // interpolation is done. In this case, an ArgbEvaluator interpolates between two 77 | // #argb values, which are specified as the 2nd and 3rd input arguments. 78 | ValueAnimator animator = ValueAnimator.ofObject(new ArgbEvaluator(), 79 | startColor.getColor(), endColor.getColor()); 80 | // Add an update listener to the Animator object. 81 | animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 82 | @Override 83 | public void onAnimationUpdate(ValueAnimator animation) { 84 | Object value = animation.getAnimatedValue(); 85 | // Each time the ValueAnimator produces a new frame in the animation, change 86 | // the background color of the target. Ensure that the value isn't null. 87 | if (null != value) { 88 | view.setBackgroundColor((Integer) value); 89 | } 90 | } 91 | }); 92 | // Return the Animator object to the transitions framework. As the framework changes 93 | // between the starting and ending layouts, it applies the animation you've created. 94 | return animator; 95 | } 96 | } 97 | // For non-ColorDrawable backgrounds, we just return null, and no animation will take place. 98 | return null; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/fragment/AutoTransitionFragment.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.transition.AutoTransition; 7 | import android.transition.Transition; 8 | import android.transition.TransitionManager; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.Button; 13 | import android.widget.LinearLayout; 14 | import android.widget.TextView; 15 | 16 | import com.hcy.huchengyang.transitionnote.R; 17 | 18 | /** 19 | * Created by huchengyang on 2017/9/21. 20 | */ 21 | 22 | public class AutoTransitionFragment extends Fragment { 23 | private Button mButton; 24 | private TextView mTextView; 25 | private LinearLayout mRoot; 26 | private Transition mTransition; 27 | @Nullable 28 | @Override 29 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 30 | View view = inflater.inflate(R.layout.fragment_auto_transition, container, false); 31 | mButton = view.findViewById(R.id.button); 32 | mTextView = view.findViewById(R.id.message); 33 | mRoot = view.findViewById(R.id.root); 34 | mTransition = new AutoTransition(); 35 | mButton.setOnClickListener(new View.OnClickListener() { 36 | @Override 37 | public void onClick(View view) { 38 | toggle(); 39 | } 40 | }); 41 | return view; 42 | } 43 | 44 | private void toggle() { 45 | TransitionManager.beginDelayedTransition(mRoot, mTransition); 46 | if (mTextView.getVisibility() != View.VISIBLE) { 47 | mTextView.setVisibility(View.VISIBLE); 48 | } else { 49 | mTextView.setVisibility(View.GONE); 50 | } 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/fragment/ChangeBoundsFragment.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.transition.ChangeBounds; 7 | import android.transition.Transition; 8 | import android.transition.TransitionManager; 9 | import android.view.Gravity; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.Button; 14 | import android.widget.FrameLayout; 15 | 16 | import com.hcy.huchengyang.transitionnote.R; 17 | 18 | /** 19 | * Created by huchengyang on 2017/9/21. 20 | */ 21 | 22 | public class ChangeBoundsFragment extends Fragment { 23 | private Button mButton; 24 | private FrameLayout mRoot; 25 | private View mTarget; 26 | private Transition mTransition; 27 | @Nullable 28 | @Override 29 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 30 | View view = inflater.inflate(R.layout.fragment_change_bounds, container, false); 31 | mRoot = view.findViewById(R.id.root); 32 | mTarget = view.findViewById(R.id.target); 33 | mButton = view.findViewById(R.id.move); 34 | mTransition = new ChangeBounds(); 35 | mButton.setOnClickListener(new View.OnClickListener() { 36 | @Override 37 | public void onClick(View view) { 38 | move(); 39 | } 40 | }); 41 | return view; 42 | } 43 | 44 | private void move() { 45 | TransitionManager.beginDelayedTransition(mRoot, mTransition); 46 | FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mTarget.getLayoutParams(); 47 | if ((lp.gravity & Gravity.START) == Gravity.START) { 48 | lp.gravity = Gravity.BOTTOM | Gravity.END; 49 | } else { 50 | lp.gravity = Gravity.TOP | Gravity.START; 51 | } 52 | mTarget.setLayoutParams(lp); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/fragment/ChangeClipBoundsFragment.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.fragment; 2 | 3 | import android.graphics.Rect; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v4.view.ViewCompat; 8 | import android.transition.ChangeClipBounds; 9 | import android.transition.Transition; 10 | import android.transition.TransitionManager; 11 | import android.util.Log; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.ImageView; 16 | import android.widget.LinearLayout; 17 | 18 | import com.hcy.huchengyang.transitionnote.R; 19 | 20 | import butterknife.BindView; 21 | import butterknife.ButterKnife; 22 | import butterknife.OnClick; 23 | 24 | /** 25 | * Created by huchengyang on 2017/9/21. 26 | */ 27 | 28 | public class ChangeClipBoundsFragment extends Fragment { 29 | @BindView(R.id.root) 30 | LinearLayout mRoot; 31 | @BindView(R.id.photo) 32 | ImageView mImageView; 33 | private Transition mTransition; 34 | private static final Rect BOUNDS = new Rect(20, 20, 100, 100); 35 | 36 | @Nullable 37 | @Override 38 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 39 | View view = inflater.inflate(R.layout.fragment_change_clip_bounds, container, false); 40 | ButterKnife.bind(this, view); 41 | mTransition = new ChangeClipBounds(); 42 | return view; 43 | } 44 | @OnClick(R.id.toggle) 45 | void toggle(){ 46 | TransitionManager.beginDelayedTransition(mRoot, mTransition); 47 | if (BOUNDS.equals(ViewCompat.getClipBounds(mImageView))) { 48 | ViewCompat.setClipBounds(mImageView, null); 49 | } else { 50 | ViewCompat.setClipBounds(mImageView, BOUNDS); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/fragment/ChangeImageTransformFragment.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.fragment; 2 | 3 | import android.graphics.Matrix; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.transition.ChangeImageTransform; 8 | import android.transition.Transition; 9 | import android.transition.TransitionManager; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.ImageView; 14 | import android.widget.LinearLayout; 15 | 16 | import com.hcy.huchengyang.transitionnote.R; 17 | 18 | import butterknife.BindView; 19 | import butterknife.ButterKnife; 20 | import butterknife.OnClick; 21 | 22 | /** 23 | * Created by huchengyang on 2017/9/21. 24 | */ 25 | 26 | public class ChangeImageTransformFragment extends Fragment { 27 | @BindView(R.id.container) 28 | LinearLayout mRoot; 29 | @BindView(R.id.photo) 30 | ImageView mImageView; 31 | private Transition mTransition; 32 | @Nullable 33 | @Override 34 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 35 | View view = inflater.inflate(R.layout.fragment_change_image_transform, container, false); 36 | ButterKnife.bind(this, view); 37 | mTransition = new ChangeImageTransform(); 38 | return view; 39 | } 40 | @OnClick(R.id.fit_xy) 41 | void fitXY(){ 42 | TransitionManager.beginDelayedTransition(mRoot, mTransition); 43 | mImageView.setScaleType(ImageView.ScaleType.FIT_XY); 44 | } 45 | @OnClick(R.id.center) 46 | void center(){ 47 | TransitionManager.beginDelayedTransition(mRoot, mTransition); 48 | mImageView.setScaleType(ImageView.ScaleType.CENTER); 49 | } 50 | @OnClick(R.id.center_crop) 51 | void centerCrop(){ 52 | TransitionManager.beginDelayedTransition(mRoot, mTransition); 53 | mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP); 54 | } 55 | @OnClick(R.id.fit_start) 56 | void fitStart(){ 57 | TransitionManager.beginDelayedTransition(mRoot, mTransition); 58 | mImageView.setScaleType(ImageView.ScaleType.FIT_START); 59 | } 60 | @OnClick(R.id.fit_end) 61 | void firEnd(){ 62 | TransitionManager.beginDelayedTransition(mRoot, mTransition); 63 | mImageView.setScaleType(ImageView.ScaleType.FIT_END); 64 | } 65 | @OnClick(R.id.matrix) 66 | void matrix(){ 67 | TransitionManager.beginDelayedTransition(mRoot, mTransition); 68 | mImageView.setScaleType(ImageView.ScaleType.MATRIX); 69 | final Matrix matrix = new Matrix(); 70 | matrix.setRotate(45.f); 71 | matrix.postTranslate(200, 10); 72 | mImageView.setImageMatrix(matrix); 73 | 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/fragment/ChangeScrollFragment.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.fragment; 2 | 3 | import android.annotation.TargetApi; 4 | import android.os.Build; 5 | import android.os.Bundle; 6 | import android.support.annotation.Nullable; 7 | import android.support.v4.app.Fragment; 8 | import android.transition.ChangeScroll; 9 | import android.transition.Transition; 10 | import android.transition.TransitionManager; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.widget.FrameLayout; 15 | 16 | import com.hcy.huchengyang.transitionnote.R; 17 | 18 | import butterknife.BindView; 19 | import butterknife.ButterKnife; 20 | import butterknife.OnClick; 21 | 22 | /** 23 | * Created by huchengyang on 2017/9/21. 24 | */ 25 | 26 | public class ChangeScrollFragment extends Fragment { 27 | 28 | @BindView(R.id.root) 29 | FrameLayout mRoot; 30 | @BindView(R.id.target) 31 | View mTarget; 32 | private Transition mTransition; 33 | @TargetApi(Build.VERSION_CODES.M) 34 | @Nullable 35 | @Override 36 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 37 | View view = inflater.inflate(R.layout.fragment_change_scroll, container, false); 38 | ButterKnife.bind(this, view); 39 | mTransition = new ChangeScroll(); 40 | return view; 41 | } 42 | @OnClick(R.id.move) 43 | void move(){ 44 | TransitionManager.beginDelayedTransition(mRoot, mTransition); 45 | mTarget.scrollBy(-100, -100); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/fragment/ChangeTransformFragment.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.transition.ChangeTransform; 7 | import android.transition.Transition; 8 | import android.transition.TransitionManager; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.FrameLayout; 13 | import android.widget.LinearLayout; 14 | 15 | import com.hcy.huchengyang.transitionnote.R; 16 | 17 | import butterknife.BindView; 18 | import butterknife.ButterKnife; 19 | import butterknife.OnClick; 20 | 21 | /** 22 | * Created by huchengyang on 2017/9/21. 23 | */ 24 | 25 | public class ChangeTransformFragment extends Fragment { 26 | @BindView(R.id.root) 27 | LinearLayout mRoot; 28 | @BindView(R.id.container_1) 29 | FrameLayout mContainer1; 30 | @BindView(R.id.container_2) 31 | FrameLayout mContainer2; 32 | private Transition mTransition; 33 | @Nullable 34 | @Override 35 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 36 | View view = inflater.inflate(R.layout.fragment_change_transform, container, false); 37 | ButterKnife.bind(this, view); 38 | mTransition = new ChangeTransform(); 39 | showRedSquare(mContainer1); 40 | return view; 41 | } 42 | @OnClick(R.id.toggle) 43 | void toggle(){ 44 | TransitionManager.beginDelayedTransition(mRoot, mTransition); 45 | if (mContainer2.getChildCount() > 0) { 46 | mContainer2.removeAllViews(); 47 | showRedSquare(mContainer1); 48 | } else { 49 | mContainer1.removeAllViews(); 50 | showRedSquare(mContainer2); 51 | mContainer2.getChildAt(0).setRotation(45); 52 | } 53 | } 54 | 55 | private void showRedSquare(FrameLayout container) { 56 | final View view = LayoutInflater.from(getContext()) 57 | .inflate(R.layout.red_square, container, false); 58 | container.addView(view); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/fragment/CustomTransitionWithSceneFragment.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.transition.Scene; 7 | import android.transition.Transition; 8 | import android.transition.TransitionManager; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.FrameLayout; 13 | 14 | import com.hcy.huchengyang.transitionnote.R; 15 | import com.hcy.huchengyang.transitionnote.custom.ChangeSceneColor; 16 | 17 | import butterknife.BindView; 18 | import butterknife.ButterKnife; 19 | import butterknife.OnClick; 20 | 21 | /** 22 | * Created by huchengyang on 2017/9/21. 23 | */ 24 | 25 | public class CustomTransitionWithSceneFragment extends Fragment { 26 | @BindView(R.id.root) 27 | FrameLayout mRoot; 28 | private Scene[] mScenes; 29 | private int mCurrentScene; 30 | private Transition mTransition; 31 | @Nullable 32 | @Override 33 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 34 | View view = inflater.inflate(R.layout.fragment_custom_transition_with_scene, container, false); 35 | ButterKnife.bind(this, view); 36 | mScenes = new Scene[]{ 37 | Scene.getSceneForLayout(mRoot, R.layout.custom0, getActivity()), 38 | Scene.getSceneForLayout(mRoot, R.layout.custom1, getActivity()), 39 | Scene.getSceneForLayout(mRoot, R.layout.custom2, getActivity()) 40 | }; 41 | mTransition = new ChangeSceneColor(); 42 | TransitionManager.go(mScenes[0], mTransition); 43 | return view; 44 | } 45 | 46 | @OnClick(R.id.root) 47 | void toggle(){ 48 | mCurrentScene = (mCurrentScene + 1) % mScenes.length; 49 | TransitionManager.go(mScenes[mCurrentScene], mTransition); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/fragment/CustomTransitionWithoutSceneFragment.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.fragment; 2 | 3 | import android.graphics.Color; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.transition.Transition; 8 | import android.transition.TransitionManager; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.LinearLayout; 13 | 14 | import com.hcy.huchengyang.transitionnote.custom.ChangeColor; 15 | import com.hcy.huchengyang.transitionnote.R; 16 | 17 | import butterknife.BindView; 18 | import butterknife.ButterKnife; 19 | import butterknife.OnClick; 20 | 21 | /** 22 | * Created by huchengyang on 2017/9/21. 23 | */ 24 | 25 | public class CustomTransitionWithoutSceneFragment extends Fragment { 26 | @BindView(R.id.container) 27 | LinearLayout mRoot; 28 | @BindView(R.id.view_1) 29 | View mView1; 30 | @BindView(R.id.view_2) 31 | View mView2; 32 | @BindView(R.id.view_3) 33 | View mView3; 34 | private Transition mTransition; 35 | 36 | @Nullable 37 | @Override 38 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 39 | View view = inflater.inflate(R.layout.fragment_custom_transition_without_scene, container, false); 40 | ButterKnife.bind(this, view); 41 | mTransition = new ChangeColor(); 42 | mTransition.setDuration(1000); 43 | return view; 44 | } 45 | 46 | @OnClick(R.id.container) 47 | void changeColor(){ 48 | TransitionManager.beginDelayedTransition(mRoot, mTransition); 49 | mView1.setBackgroundColor(Color.GREEN); 50 | mView2.setBackgroundColor(Color.BLUE); 51 | mView3.setBackgroundColor(Color.RED); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/fragment/ExplodeFadeSlideFragment.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.transition.Explode; 7 | import android.transition.Fade; 8 | import android.transition.Slide; 9 | import android.transition.Transition; 10 | import android.transition.TransitionManager; 11 | import android.transition.TransitionSet; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.FrameLayout; 16 | 17 | import com.hcy.huchengyang.transitionnote.R; 18 | 19 | import java.util.ArrayList; 20 | 21 | import butterknife.BindView; 22 | import butterknife.ButterKnife; 23 | import butterknife.OnClick; 24 | 25 | /** 26 | * Created by huchengyang on 2017/9/21. 27 | */ 28 | 29 | public class ExplodeFadeSlideFragment extends Fragment { 30 | 31 | @BindView(R.id.root) 32 | FrameLayout mRoot; 33 | @BindView(R.id.view_1) 34 | View view1; 35 | @BindView(R.id.view_2) 36 | View view2; 37 | @BindView(R.id.view_3) 38 | View view3; 39 | @BindView(R.id.view_4) 40 | View view4; 41 | private ArrayList mViews = new ArrayList<>(); 42 | private Transition mTransition; 43 | @Nullable 44 | @Override 45 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 46 | View view = inflater.inflate(R.layout.fragment_explode, container, false); 47 | ButterKnife.bind(this, view); 48 | if (mViews.isEmpty()){ 49 | mViews.add(view1); 50 | mViews.add(view2); 51 | mViews.add(view3); 52 | mViews.add(view4); 53 | } 54 | // mTransition = new Explode(); 55 | //mTransition = new Fade(); 56 | mTransition = new Slide(); 57 | return view; 58 | } 59 | 60 | @OnClick(R.id.toggle) 61 | void toggle(){ 62 | TransitionManager.beginDelayedTransition(mRoot, mTransition); 63 | int vis = mViews.get(0).getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE; 64 | for (View view : mViews) { 65 | view.setVisibility(vis); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/fragment/MainFragment.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.fragment; 2 | 3 | import android.content.Context; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.ListFragment; 7 | import android.view.View; 8 | import android.widget.ArrayAdapter; 9 | import android.widget.ListView; 10 | 11 | import com.hcy.huchengyang.transitionnote.R; 12 | 13 | /** 14 | * Created by huchengyang on 2017/9/20. 15 | */ 16 | public class MainFragment extends ListFragment { 17 | private OnListItemClickListener onListItemClickListener; 18 | 19 | public interface OnListItemClickListener{ 20 | void onListItemClick(int position); 21 | } 22 | 23 | public MainFragment(){} 24 | 25 | @Override 26 | public void onAttach(Context context) { 27 | super.onAttach(context); 28 | onListItemClickListener = (OnListItemClickListener) context; 29 | } 30 | 31 | @Override 32 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 33 | super.onActivityCreated(savedInstanceState); 34 | String listData[] = getResources().getStringArray(R.array.list_name); 35 | ArrayAdapter adapter = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_1, listData); 36 | setListAdapter(adapter); 37 | } 38 | 39 | @Override 40 | public void onListItemClick(ListView l, View v, int position, long id) { 41 | onListItemClickListener.onListItemClick(position); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/fragment/PathMotionFragment.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.transition.ArcMotion; 6 | import android.transition.AutoTransition; 7 | import android.transition.ChangeBounds; 8 | import android.transition.PatternPathMotion; 9 | import android.transition.Transition; 10 | import android.transition.TransitionManager; 11 | import android.view.Gravity; 12 | import android.view.LayoutInflater; 13 | import android.view.View; 14 | import android.view.ViewGroup; 15 | import android.widget.FrameLayout; 16 | import android.widget.TextView; 17 | 18 | import com.hcy.huchengyang.transitionnote.R; 19 | 20 | import butterknife.BindView; 21 | import butterknife.ButterKnife; 22 | import butterknife.OnClick; 23 | 24 | 25 | /** 26 | * Created by huchengyang on 2017/9/20. 27 | */ 28 | 29 | public class PathMotionFragment extends Fragment { 30 | @BindView(R.id.root) 31 | FrameLayout mRoot; 32 | @BindView(R.id.target) 33 | TextView mTarget; 34 | private Transition mTransition; 35 | @Override 36 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 37 | View view = inflater.inflate(R.layout.fragment_path_motion, container, false); 38 | ButterKnife.bind(this, view); 39 | mTransition = new AutoTransition(); 40 | mTransition.setPathMotion(new ArcMotion()); 41 | //mTransition.setPathMotion(new PatternPathMotion()); 42 | mTransition.setDuration(1000); 43 | return view; 44 | } 45 | 46 | @OnClick(R.id.move) 47 | void toggle(){ 48 | TransitionManager.beginDelayedTransition(mRoot, mTransition); 49 | FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mTarget.getLayoutParams(); 50 | if ((lp.gravity & Gravity.START) == Gravity.START) { 51 | lp.gravity = Gravity.END | Gravity.BOTTOM; 52 | } else { 53 | lp.gravity = Gravity.START | Gravity.TOP; 54 | } 55 | mTarget.setLayoutParams(lp); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/fragment/SceneFragment.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.transition.Fade; 7 | import android.transition.Scene; 8 | import android.transition.Transition; 9 | import android.transition.TransitionManager; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.Button; 14 | import android.widget.FrameLayout; 15 | 16 | import com.hcy.huchengyang.transitionnote.R; 17 | 18 | /** 19 | * Created by huchengyang on 2017/9/20. 20 | */ 21 | 22 | public class SceneFragment extends Fragment { 23 | private FrameLayout mSceneRoot; 24 | private Scene[] mScenes; 25 | private Scene mScene0; 26 | private Scene mScene1; 27 | private Transition mTransition; 28 | private Button mButton; 29 | private int mCurrentScene; 30 | @Nullable 31 | @Override 32 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 33 | View view = inflater.inflate(R.layout.fragment_scene, container, false); 34 | mButton = view.findViewById(R.id.toggle); 35 | mSceneRoot = view.findViewById(R.id.root); 36 | /*View view0 = inflater.inflate(R.layout.scene0, container, false); 37 | View view1 = inflater.inflate(R.layout.scene1, container, false); 38 | mScene0 = new Scene(mSceneRoot, view0); 39 | mScene1 = new Scene(mSceneRoot, view1);*/ 40 | mScene0 = Scene.getSceneForLayout(mSceneRoot, R.layout.scene0, getContext()); 41 | mScene1 = Scene.getSceneForLayout(mSceneRoot, R.layout.scene1, getContext()); 42 | mScenes = new Scene[]{mScene0, mScene1}; 43 | mTransition = new Fade(); 44 | TransitionManager.go(mScenes[0]); 45 | mButton.setOnClickListener(new View.OnClickListener() { 46 | @Override 47 | public void onClick(View view) { 48 | mCurrentScene = (mCurrentScene + 1) % mScenes.length; 49 | TransitionManager.go(mScenes[mCurrentScene]); 50 | } 51 | }); 52 | 53 | return view; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/hcy/huchengyang/transitionnote/fragment/TransitionSetFragment.java: -------------------------------------------------------------------------------- 1 | package com.hcy.huchengyang.transitionnote.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.transition.ChangeImageTransform; 7 | import android.transition.ChangeTransform; 8 | import android.transition.TransitionInflater; 9 | import android.transition.TransitionManager; 10 | import android.transition.TransitionSet; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.ViewGroup; 14 | import android.widget.FrameLayout; 15 | import android.widget.ImageView; 16 | 17 | import com.hcy.huchengyang.transitionnote.R; 18 | 19 | import butterknife.BindView; 20 | import butterknife.ButterKnife; 21 | import butterknife.OnClick; 22 | 23 | /** 24 | * Created by huchengyang on 2017/9/21. 25 | */ 26 | 27 | public class TransitionSetFragment extends Fragment { 28 | @BindView(R.id.outer_frame) 29 | FrameLayout mOuterFrame; 30 | @BindView(R.id.inner_frame) 31 | FrameLayout mInnerFrame; 32 | private TransitionSet mTransition; 33 | int mPhotoSize; 34 | @Nullable 35 | @Override 36 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 37 | View view = inflater.inflate(R.layout.fragment_transition_set, container, false); 38 | ButterKnife.bind(this, view); 39 | mPhotoSize = getResources().getDimensionPixelSize(R.dimen.photo_size); 40 | mTransition = new TransitionSet(); 41 | mTransition.addTransition(new ChangeImageTransform()); 42 | mTransition.addTransition(new ChangeTransform()); 43 | //mTransition = (TransitionSet) TransitionInflater.from(getContext()).inflateTransition(R.transition.transition); 44 | addImageView(mOuterFrame, ImageView.ScaleType.CENTER_CROP, mPhotoSize); 45 | return view; 46 | } 47 | 48 | private void addImageView(FrameLayout parent, ImageView.ScaleType scaleType, int size) { 49 | final ImageView photo = new ImageView(getContext()); 50 | photo.setImageResource(R.drawable.photo); 51 | photo.setId(R.id.photo); 52 | photo.setScaleType(scaleType); 53 | FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(size, size); 54 | parent.addView(photo, lp); 55 | } 56 | 57 | @OnClick(R.id.toggle) 58 | void toggle(){ 59 | TransitionManager.beginDelayedTransition(mOuterFrame, mTransition); 60 | if (mInnerFrame.getChildCount() > 0) { 61 | mInnerFrame.removeAllViews(); 62 | addImageView(mOuterFrame, ImageView.ScaleType.CENTER_CROP, mPhotoSize); 63 | } else { 64 | mOuterFrame.removeViewAt(1); 65 | addImageView(mInnerFrame, ImageView.ScaleType.FIT_XY, 66 | FrameLayout.LayoutParams.MATCH_PARENT); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-nodpi/photo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Rkhcy/TransitionNote/2eaabcec9e97c3248e198e754296243b171ae225/app/src/main/res/drawable-nodpi/photo.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 12 | 17 | 22 | 27 | 32 | 37 | 42 | 47 | 52 | 57 | 62 | 67 | 72 | 77 | 82 | 87 | 92 | 97 | 102 | 107 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/custom0.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 23 | 24 | 30 | 31 | 37 | 38 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /app/src/main/res/layout/custom1.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 23 | 24 | 30 | 31 | 37 | 38 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /app/src/main/res/layout/custom2.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 23 | 24 | 30 | 31 | 37 | 38 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_auto_transition.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 21 | 22 | 29 | 30 | 37 | 38 |