user2999943
user2999943

Reputation: 2519

Android shared element transition not working with different img scale types

I want to perform shared element transition when switching from Activity A to Activity B. The problem is that transition animation is not working smoothly when shared imageViews scale types are different. I am noticing a "bounce" in the very beginning of transition (on not animated imageView scaleType change I guess). The same "bounce" I am noticing when coming back from Activity B to Activity A.

Details:

Activity A contains imageView with scaleType: centerCrop. Actvity B contains imageView with scaleType: fitXY.

Both ImageView have android:transitionName="sharedView", of course.

My transition set in xml looks like this:

<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
   <changeBounds/>
   <changeImageTransform/>
</transitionSet>

In documentation about this config is written:

In combination with ChangeBounds, ChangeImageTransform allows ImageViews that change size, shape, or ImageView.ScaleType to animate contents smoothly.

So why my transition is not working smoothly? Or how to animate scaleType change during shared element transition if changeBounds with changeImageTransform doesn't seem to work?

Worth to mention that if I make scale types equal (e.g. centerCrop and centerCrop) of shared views - then transition works smoothly and everything is ok.

Upvotes: 5

Views: 2167

Answers (2)

Tam Huynh
Tam Huynh

Reputation: 2487

I've solved this problem in my case. Here is something you need to check:

  • Make sure your Shared element is ImageView for both source and target activity (Don't use any container).
  • Set the transitionName for the ImageView (not its container).

After I updated this, changeImageTransform will do its job changing scaleType smoothly between 2 ImageViews

Upvotes: 0

Ircover
Ircover

Reputation: 2446

Had same problem. Solved it by setting same padding property for both ImageView's. I don't know why it works so, but hope it can help someone.

Upvotes: -2

Related Questions