How to implement a parent-to-child navigation transition as prescribed by Material Design

The Google Material Design Guides prescribe the next transition for parent-to-child transitions when the parent list consists of a list. (Material Design Guide)

How can I ensure such a transition? I do not know about any built-in transitions to make this possible.

+7
android material-design
source share
2 answers

One option is to use ActivityOptionsCompat.makeScaleUpAnimation

 Activity activity = getActivity(); Intent intent = new Intent(activity, OtherActivity.class); Bundle options = ActivityOptionsCompat.makeScaleUpAnimation( sourceView, 0, 0, sourceView.getWidth(), sourceView.getHeight()).toBundle(); ActivityCompat.startActivity(activity, intent, options); 

This will cause the new action to expand vertically and horizontally outward from your sourceView

+2
source share

Run an action with a common item

Make a screen transition animation between two actions that share a common element:

Enable window content transitions in your theme. Indicate the overall transition of elements in your style. Define your transition as an XML resource. Assign a common name for common elements in both layouts using the android: transitionName attribute. Use the ActivityOptions.makeSceneTransitionAnimation () method.

 // get the element that receives the click event final View imgContainerView = findViewById(R.id.img_container); // get the common element for the transition in this activity final View androidRobotView = findViewById(R.id.image_small); // define a click listener imgContainerView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(this, Activity2.class); // create the transition animation - the images in the layouts // of both activities are defined with android:transitionName="robot" ActivityOptions options = ActivityOptions .makeSceneTransitionAnimation(this, androidRobotView, "robot"); // start the new activity startActivity(intent, options.toBundle()); } }); 

For the general dynamic views that you generate in your code, use the View.setTransitionName () method to specify the common name of the element in both actions.

To cancel the scene transition animation after completing the second action, call the Activity.finishAfterTransition () method instead of Activity.finish ().

Take from here Set up activity transitions

+1
source share

All Articles