Mistake:

Process: pc.dd.fragment_animation, PID: 22407 java.lang.IllegalArgumentException: Shared element must not be null ...at pc.dd.fragment_animation.MainClass$1.onClick(MainClass.java:91) 

Master Activation Xml:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="pc.dd.fragment_animation.MainClass"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="fill_parent" android:layout_height="200dp" android:transitionName="source2" android:id="@+id/source" android:layout_gravity="center_horizontal" android:src="@drawable/image1" android:scaleType="center" /> </LinearLayout> 

Activation code 2 on which we go after the animation:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="wrap_content" android:layout_height="200dp" android:id="@+id/image_target" android:layout_gravity="center_horizontal" android:transitionName="tar" android:src="@drawable/image1" android:scaleType="center" /> 

OnCreate code:

 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_class); final View photo = findViewById (R.id.image_target); final ImageView image = (ImageView) findViewById(R.id.source); image.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainClass.this, Second_Activity.class); intent.setAction(intent.ACTION_VIEW); intent.putExtra(MainClass.this.EXTRA_PHOTO, R.drawable.image1); //String transitionName = (String) findViewById(R.id.image_target); startActivity(intent, ActivityOptions.makeSceneTransitionAnimation( MainClass.this, photo , "tar" ).toBundle()); } }); 

What is wrong, can not understand?

    1 answer 1

    You don’t have an image_target element in the markup of the main activation, and you are trying to find it and transfer it to the transition animation. If the source element should turn into a new activation in image_target, then you should transfer it to an animation. Yes, and it seems to me the transition will work if you simply change the android:transitionName="source2" to android:transitionName="tar" and the code that generates ActivityOptions.

    • so I must also transfer to the function makeSceneTransitionAnimation image which is not located on the main avtiviti but an image with the activit to which I later transfer, right? - Diha-o
    • Not so, you have to transfer there elements which should be animated move to a new activation from the old one. In addition, until a new activation is created, you will not receive its elements in any way. findViewById searches for items on the current activity. Well, if in the old and new markup the elements have the same values ​​in the android:transitionName attribute, then they seem to be automatically picked up by the transition animation. But I’m not sure of that. I haven’t worked at all with these animations yet. - xkor