ActivityOptions.makeSceneTransitionAnimation does not exist

Android L introduced a new animation feature: animation between similar views in different actions. He documented here .

I tried using ActivityOptions.makeSceneTransitionAnimation , but it does not seem visible in the SDK (or in the bank at all), so I tried to use reflection, and it returns a null value.

Has anyone else earned?

+6
source share
3 answers

Ok, I started to work.

It seems that setting the value in styles.xml is completely ignored.

You will need to do this in every onCreate action while this is fixed.

 getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS); Transition transition = // load transition here. getWindow().setSharedElementEnterTransition(transition); getWindow().setSharedElementExitTransition(transition); 

According to the same ViewAnimationUtils error, you will see errors in Android Studio, it will compile and work fine, though.

+9
source

We can get it to work with theme customization for v21. Put these elements in res / values-v21 / styles.xml

  <item name="android:windowContentTransitions">true</item> <item name="android:windowAllowEnterTransitionOverlap">true</item> <item name="android:windowAllowReturnTransitionOverlap">true</item> 
+5
source

Here is something working with the 5.0 sdk received after 10/17/14.

But I'm not sure what the expected behavior is if you allow the transition of the contents of the window and is called setEnterTransition / setExitTransition both mainActivity and secondActivity . If they are different (for example, one of them chooses Explode and the other chooses Slide), which one will be used?

 public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /* To enable window content transitions in your code instead, call the Window.requestFeature() method: */ getWindow().requestFeature(android.view.Window.FEATURE_CONTENT_TRANSITIONS); Transition ts = new Explode(); //Slide(); //Explode(); ts.setStartDelay(2000); ts.setDuration(5000); /* If you have set an enter transition for the second activity, the transition is also activated when the activity starts. */ getWindow().setEnterTransition(ts); getWindow().setExitTransition(ts); setContentView(R.layout.activity_main_view); if (savedInstanceState == null) { getFragmentManager().beginTransaction() .add(R.id.container, mainViewFragment.newInstance()) .commit(); } } public void launchSecondActivity() { /* If you enable transitions and set an exit transition for an activity, the transition is activated when you launch another activity as follows: */ Intent listIntent = new Intent(this, secondActivity.class); startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(this).toBundle()); } } 

// ===

 public class secondActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); /// getWindow().requestFeature(android.view.Window.FEATURE_CONTENT_TRANSITIONS); Transition ts = new Slide(); //Slide(); //Explode(); ts.setDuration(3000); getWindow().setEnterTransition(ts); getWindow().setExitTransition(ts); /// setContentView(R.layout.activity_scene_transition); if (savedInstanceState == null) { getFragmentManager().beginTransaction() .add(R.id.container, new PlaceholderFragment()) .commit(); } } 
+2
source

Source: https://habr.com/ru/post/971615/


All Articles