jobin
jobin

Reputation: 1527

Android shared element transition does not work

I have 2 Activities each having an ImageView.First one has an image which upon clicked should do the transition magic while moving to the next activity.It goes to the next activity,but for some strange reason transition is not working.

Activity1 Screenshot:

enter image description here

Activity2 Screenshot

enter image description here

Activity1.java:

if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP)
                {
                    Intent intent =new Intent(Activity1.this,Activity2.class);
                    ActivityOptionsCompat activityOptions=ActivityOptionsCompat.
                            makeSceneTransitionAnimation(Activity1.this,imageView,"shift");

                    ActivityCompat.startActivity(Activity1.this,intent,activityOptions.toBundle());
                }

activity1.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/img"
    android:layout_centerHorizontal="true"
    android:background="@drawable/th"
    android:transitionName="shift"/>
</RelativeLayout>

activity2.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/img1"
    android:layout_alignParentBottom="true"
    android:transitionName="shift"/>
</RelativeLayout>

Upvotes: 0

Views: 132

Answers (2)

Devendra
Devendra

Reputation: 3454

You are not setting image for ImageView in your actvity2.xml

Add this in your ImageView of actvity2.xml:

android:background="@drawable/th"

Upvotes: 1

Kriczer
Kriczer

Reputation: 517

In order to use element transition you must add windowActivityTransitions attribute to your app Theme.

  <!-- enable window content transitions -->
  <item name="android:windowActivityTransitions">true</item>

Also look at official Android doc: Start an activity using an animation .

Upvotes: 0

Related Questions