BigDX
BigDX

Reputation: 3547

Android shared element transition on ImageView scale is wrong

I have tried many different variations and cannot get the return transition to work properly.

When i exit Activity B the image transitions back to Activity A but it is scaled until it disappears then after disappearing is shows where it should.

I have tried different variations of the following and others in that group

Activity A Coming from click listener in recyclerview.

Intent intent = new Intent(getActivity(), ApplyActivity.class);
            ActivityOptionsCompat transitionActivityOptions;
            transitionActivityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(), imageView, getString(R.string.transition_image_details));
            intent.putExtra(ApplyActivity.EXTRA_NAME, selected_launcher);
            intent.putExtra(ApplyActivity.EXTRA_INSTALLED, mLaunchers.get(position).getInstalled());

            getActivity().startActivity(intent, transitionActivityOptions.toBundle());

Activity A layout

<ImageView
android:id="@+id/launcher_icon"
android:transitionName="@string/transition_image_details"
android:layout_width="72dp"
android:layout_height="72dp"
android:layout_centerHorizontal="true"
android:padding="@dimen/small_padding"
android:layout_alignParentTop="true" />

Activity B

 Transition transition = TransitionInflater.from(this).inflateTransition(R.transition.change_image_transform);

        getWindow().setSharedElementReturnTransition(transition);
        getWindow().setSharedElementEnterTransition(transition);
        getWindow().setSharedElementExitTransition(transition);

I have tried the following true/false getWindow().setSharedElementsUseOverlay(true);

Activity B layout (within an AppBarLayout/CollapsingToolbarLayout)

<ImageView
   android:id="@+id/backdrop"
   android:transitionName="@string/transition_image_details"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:paddingBottom="80dp"
   android:paddingTop="30dp"
   app:layout_collapseMode="parallax"
   app:layout_collapseParallaxMultiplier="0.7" />

change_image_transform.xml

<?xml version="1.0" encoding="utf-8"?>
<transitionSet xmlns:android="http://schemas.android.com/apk/res/android">
<changeTransform  />
<changeImageTransform />
</transitionSet>

I have tried setting the transition in values-v21/styles.xml too with no luck.

I have even tried setting the position from the recyclerview the transition name with no luck either.

Here is a video of the issue. I slowed down the transition so it could be seen better

https://www.dropbox.com/s/gzli11ae3ebz95f/2016_04_19_20_33_29.mp4?dl=0

Upvotes: 5

Views: 4516

Answers (2)

Ornithopter
Ornithopter

Reputation: 2088

Make sure the two images share the same scaleType.

Refer to this post for more info: Android Glide library not working with shared element transitions

Upvotes: 4

Xiaoyong
Xiaoyong

Reputation: 1

You can try removing these transiton codes in Activity B.I done that, and it worked well.

Upvotes: -2

Related Questions