/** * 设置自定义 Shared Element切换动画 * 默认不开启曲线路径切换动画, * 开启需要重写setHeaderPicView(),和调用此方法并将isShow值设为true * * @param imageView 共享的图片 * @param isShow 是否显示曲线动画 */ protected void setMotion(ImageView imageView, boolean isShow) { if (!isShow) { return; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //定义ArcMotion ArcMotion arcMotion = new ArcMotion(); arcMotion.setMinimumHorizontalAngle(50f); arcMotion.setMinimumVerticalAngle(50f); //插值器,控制速度 Interpolator interpolator = AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in); //实例化自定义的ChangeBounds CustomChangeBounds changeBounds = new CustomChangeBounds(); changeBounds.setPathMotion(arcMotion); changeBounds.setInterpolator(interpolator); changeBounds.addTarget(imageView); //将切换动画应用到当前的Activity的进入和返回 getWindow().setSharedElementEnterTransition(changeBounds); getWindow().setSharedElementReturnTransition(changeBounds); } }
/** * 设置自定义 Shared Element切换动画 */ private void setMotion() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { //定义ArcMotion ArcMotion arcMotion = new ArcMotion(); arcMotion.setMinimumHorizontalAngle(50f); arcMotion.setMinimumVerticalAngle(50f); //插值器,控制速度 Interpolator interpolator = AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in); //实例化自定义的ChangeBounds CustomChangeBounds changeBounds = new CustomChangeBounds(); changeBounds.setPathMotion(arcMotion); changeBounds.setInterpolator(interpolator); changeBounds.addTarget(binding.include.ivOnePhoto); //将切换动画应用到当前的Activity的进入和返回 getWindow().setSharedElementEnterTransition(changeBounds); getWindow().setSharedElementReturnTransition(changeBounds); } }
public void setupSharedEelementTransitions() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; //Show dialog normally if below Lollipop ArcMotion arcMotion = new ArcMotion(); arcMotion.setMinimumHorizontalAngle(50f); arcMotion.setMinimumVerticalAngle(50f); Interpolator easeInOut = AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in); MorphFabToDialog sharedEnter = new MorphFabToDialog(getBackgroundColor()); sharedEnter.setPathMotion(arcMotion); sharedEnter.setInterpolator(easeInOut); MorphDialogToFab sharedReturn = new MorphDialogToFab(getBackgroundColor()); sharedReturn.setPathMotion(arcMotion); sharedReturn.setInterpolator(easeInOut); if (ui.container != null) { sharedEnter.addTarget(ui.container); sharedReturn.addTarget(ui.container); } getWindow().setSharedElementEnterTransition(sharedEnter); getWindow().setSharedElementReturnTransition(sharedReturn); }
@OnClick(R.id.square2) public void onClick() { FragmentSharedElementTransitionTarget targetFragment = new FragmentSharedElementTransitionTarget(); // FIXME: 08/02/2017 the shared element transitions to the next fragment below other views while it should be on top as in Activity transitions if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { TransitionSet transitionSet = new TransitionSet(); transitionSet.addTransition(new ChangeBounds()); transitionSet.setPathMotion(new ArcMotion()); targetFragment.setSharedElementEnterTransition(transitionSet); targetFragment.setSharedElementReturnTransition(transitionSet); targetFragment.setEnterTransition(TransitionInflater.from(getActivity()).inflateTransition(R.transition.slide_bottom)); targetFragment.setExitTransition(TransitionInflater.from(getActivity()).inflateTransition(R.transition.slide_top_and_fade)); setExitTransition(new Explode()); setReenterTransition(new Explode()); setAllowReturnTransitionOverlap(false); } getActivity().getSupportFragmentManager() .beginTransaction() .addSharedElement(square2, getString(R.string.custom_element_transition_name)) .replace(R.id.fragmentContainer, targetFragment) .addToBackStack(null) .commit(); }
/** * 使用方式一:调用setupSharedEelementTransitions1方法 * 使用这种方式的话需要的类是 MorphDrawable, MorphFabToDialog, MorphDialogToFab */ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void setupSharedEelementTransitions1() { ArcMotion arcMotion = new ArcMotion(); arcMotion.setMinimumHorizontalAngle(50f); arcMotion.setMinimumVerticalAngle(50f); Interpolator easeInOut = AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in); MorphFabToDialog sharedEnter = new MorphFabToDialog(); sharedEnter.setPathMotion(arcMotion); sharedEnter.setInterpolator(easeInOut); MorphDialogToFab sharedReturn = new MorphDialogToFab(); sharedReturn.setPathMotion(arcMotion); sharedReturn.setInterpolator(easeInOut); if (container != null) { sharedEnter.addTarget(container); sharedReturn.addTarget(container); } getWindow().setSharedElementEnterTransition(sharedEnter); getWindow().setSharedElementReturnTransition(sharedReturn); }
@NonNull @Override protected Transition createTransition(@NonNull ViewGroup container, @NonNull View entering, @Nullable View leaving, boolean push) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { return new TransitionSet() .setOrdering(ORDERING_TOGETHER) .addTransition(new Fade(Fade.OUT)) .addTransition(new Fade(Fade.IN)); } final TransitionSet transition = new TransitionSet() .addTransition(new ChangeBounds()) .addTransition(new ChangeClipBounds()) .addTransition(new ChangeTransform()); transition.setPathMotion(new ArcMotion()); return transition; }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void setMotion() { // Activity设置自定义 Shared Element切换动画 //定义ArcMotion ArcMotion arcMotion = new ArcMotion(); arcMotion.setMinimumHorizontalAngle(50f); arcMotion.setMinimumVerticalAngle(50f); //插值器,控制速度 Interpolator interpolator = AnimationUtils .loadInterpolator(this, android.R.interpolator.fast_out_slow_in); //实例化自定义的ChangeBounds CustomChangeBounds changeBounds = new CustomChangeBounds(); changeBounds.setPathMotion(arcMotion); changeBounds.setInterpolator(interpolator); changeBounds.addTarget(mBinding.comicThumbnailComicDetails); //将切换动画应用到当前的Activity的进入和返回 getWindow().setSharedElementEnterTransition(changeBounds); getWindow().setSharedElementReturnTransition(changeBounds); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_custom_transition_second); ViewGroup container = (ViewGroup) findViewById(R.id.container); getSupportActionBar().setTitle("第二个Activity"); /* 自定义 Shared Element切换动画 */ //定义ArcMotion ArcMotion arcMotion = new ArcMotion(); arcMotion.setMinimumHorizontalAngle(50f); arcMotion.setMinimumVerticalAngle(50f); // 设置插值器 - 慢进快出 Interpolator interpolator = AnimationUtils .loadInterpolator(this, android.R.interpolator.fast_out_slow_in); //实例化自定义的ChangeBounds CustomChangeBounds changeBounds = new CustomChangeBounds(); changeBounds.setPathMotion(arcMotion); changeBounds.setInterpolator(interpolator); changeBounds.addTarget(container); //将切换动画应用到当前的Activity的进入和返回 getWindow().setSharedElementEnterTransition(changeBounds); getWindow().setSharedElementReturnTransition(changeBounds); }
@Override @NonNull protected Transition getTransition(@NonNull ViewGroup container, View from, View to, boolean isPush) { TransitionSet transition = new TransitionSet() .setOrdering(TransitionSet.ORDERING_SEQUENTIAL) .addTransition(new Fade(Fade.OUT)) .addTransition(new TransitionSet().addTransition(new ChangeBounds()).addTransition(new ChangeClipBounds()).addTransition(new ChangeTransform())) .addTransition(new Fade(Fade.IN)); transition.setPathMotion(new ArcMotion()); return transition; }
/** * 使用方式二:调用setupSharedEelementTransitions2方法 * 使用这种方式的话需要的类是 MorphDrawable, MorphTransition */ @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void setupSharedEelementTransitions2() { ArcMotion arcMotion = new ArcMotion(); arcMotion.setMinimumHorizontalAngle(50f); arcMotion.setMinimumVerticalAngle(50f); Interpolator easeInOut = AnimationUtils.loadInterpolator(this, android.R.interpolator.fast_out_slow_in); //hujiawei 100是随意给的一个数字,可以修改,需要注意的是这里调用container.getHeight()结果为0 MorphTransition sharedEnter = new MorphTransition(ContextCompat.getColor(this, R.color.colorPrimary), ContextCompat.getColor(this, R.color.white), 100, getResources().getDimensionPixelSize(R.dimen.dialog_corners), true); sharedEnter.setPathMotion(arcMotion); sharedEnter.setInterpolator(easeInOut); MorphTransition sharedReturn = new MorphTransition(ContextCompat.getColor(this, R.color.colorPrimary), ContextCompat.getColor(this, R.color.white), getResources().getDimensionPixelSize(R.dimen.dialog_corners), 100, false); sharedReturn.setPathMotion(arcMotion); sharedReturn.setInterpolator(easeInOut); if (container != null) { sharedEnter.addTarget(container); sharedReturn.addTarget(container); } getWindow().setSharedElementEnterTransition(sharedEnter); getWindow().setSharedElementReturnTransition(sharedReturn); }
public ImageTransition() { setOrdering(ORDERING_TOGETHER); addTransition(new ChangeBounds()); addTransition(new ChangeTransform()); addTransition(new ChangeImageTransform()); setPathMotion(new ArcMotion()); }
public ArcMotion() { }
public ArcMotion(Context context, AttributeSet attrs) { super(context, attrs); }
/** * Configure the shared element transitions for morphin from a fab <-> dialog. We need to do * this in code rather than declaratively as we need to supply the color to transition from/to * and the dialog corner radius which is dynamically supplied depending upon where this screen * is launched from. */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) public static void setupSharedElementTransitions(@NonNull Activity activity, @Nullable View mockFab, int dialogCornerRadius) { if (!activity.getIntent().hasExtra(EXTRA_SHARED_ELEMENT_START_COLOR)) return; int startCornerRadius = activity.getIntent() .getIntExtra(EXTRA_SHARED_ELEMENT_START_CORNER_RADIUS, -1); ArcMotion arcMotion = new ArcMotion(); arcMotion.setMinimumHorizontalAngle(5f); arcMotion.setMinimumVerticalAngle(10f); arcMotion.setMaximumAngle(10f); int color = activity.getIntent().getIntExtra(EXTRA_SHARED_ELEMENT_START_COLOR, Color.TRANSPARENT); Interpolator easeInOut = AnimationUtils.loadInterpolator(activity, android.R.interpolator.fast_out_slow_in); MorphFabToDialog sharedEnter = new MorphFabToDialog(color, dialogCornerRadius, startCornerRadius); sharedEnter.setPathMotion(arcMotion); sharedEnter.setInterpolator(easeInOut); MorphDialogToFab sharedReturn = new MorphDialogToFab(color, startCornerRadius); sharedReturn.setPathMotion(arcMotion); sharedReturn.setInterpolator(easeInOut); if (mockFab != null) { sharedEnter.addTarget(mockFab); sharedReturn.addTarget(mockFab); } TransitionSet set = new TransitionSet(); set.addTransition(sharedEnter); //TODO: Elevation flicker is due to FAB still visible set.addTransition(new ChangeElevation()); TransitionSet set2 = new TransitionSet(); set2.addTransition(sharedReturn); set2.addTransition(new ChangeElevation()); activity.getWindow().setSharedElementEnterTransition(set); activity.getWindow().setSharedElementReturnTransition(set2); }
@Override protected Transition createTransition() { final Transition transition = new ChangeBounds(); transition.setPathMotion(new ArcMotion()); transition.setDuration(500); return transition; }