Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageView shared element transition (between Activity) starts with wrong scaleType

I found the problem with SimpleDraweeView of fresco at the beginning. However the problem still exists after I replace with android ImageView. So I can't be sure whether the problem is due to Android or just fresco.

What the problem is

  1. The first activity has recycled view and each view has a ImageView (or SimpleDraweeView). The wanted scaleType is "centerCrop"
  2. The second activity has only one ImageView. The wanted scaleType is "fitCenter"

However in my private project, and also in the sample project.
https://github.com/JackFan-Z/ActivitySharedElementTransition
The ImageView starts with scaleType "fitCenter", which is wrong.

I tried to postpone shared element transition and set different scaleType of shared element in the callbacks of SharedElementCallback. But none of them really works. Could anyone help figure out what goes wrong, or where to debug?

The screenshots of the issue

The screenshot of the first Activity:
enter image description here

The screenshot of transition:
enter image description here

like image 441
Jack Fan Avatar asked Oct 01 '15 07:10

Jack Fan


People also ask

Can activitya and activityb imageview have different transition names?

The transitionName has to be unique on the screen to any other element transitions you have. Otherwise you’ll just confuse the framework and may get some weird results. in the view hierarchy. That means that ActivityA and ActivityB ImageView can have different transitionName.

When to use shared element transition animation in Android?

This type of animation is used when we have to open an item from a ListView or RecyclerView. Shared Element Transition in Android determines how shared element views are animated from activity to activity or fragment to fragment.

How to animate multiple elements from the source view hierarchy?

Multiple Shared Elements Sometimes, you might want to animate multiple elements from the source view hierarchy. This can be achieved by using distinct transition names in the source and target layout xml files. Note: By default android.util.Pair will be imported but we want to select the android.support.v4.util.Pair class instead.

How to transition from one activity to another using shared element?

Shared element transitions between activities has a sane default transition, that works pretty much as expected. For fragments, however, you have to specify a Transition. We define a transition set in res/transition, called change_image_trans.


Video Answer


1 Answers

As you observed with ImageView this is an Android limitation. However, I am doing some changes to Fresco scale types and it will be possible to do this once I push my changes.

In short, instead of ScaleType being an Enum (which is very inflexible), ScaleType is changed to be an interface that can be implemented to do arbitrary scaling. This change has been landed internally and will soon be pushed to GitHub.

In addition to the above, I am working on the implementation of InterpolatingScaleType that just interpolates between the two underlying scale types based on the interpolation value (0.0 - 1.0). Value of 0.0 returns the same transform as the underlying scaleType1, whereas value of 1.0 returns the same transform as the underlying scaleType2. Inbetween values are a linear combination between the two.

InterpolatingScaleType allows to smoothly interpolate between the two different scale types which is handy in animations such as when doing a view transition.

Once this is ready I will update this answer.

EDIT:

@burzumrus was kind enough to provide an implementation that you can find here on GitHub. There is also a thread on this issue on the Fresco's GitHub page.

like image 55
plamenko Avatar answered Oct 22 '22 18:10

plamenko