Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude BottomNavigation from Transition Animations in Android

I've been searching all around but I can't find an answer that helps solve this particular problem. My application has a custom slide-in, slide-out effect used like this:

Intent intent = new Intent(getApplicationContext(), MyActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.slide_right_in, R.anim.slide_right_out);

The Problem

The problem is I have a BottomNavigation included in all activities, and I don't want it to get animated, I want to exclude it.

enter image description here

What I'm trying to achieve

I want to exclude the Bottom Navigation from the animation. Or, in other words, how can I only animate the content between transitions?

enter image description here

EDIT: I already tried doing with Shared Element, but I wanted it to work below API 21.

like image 603
Pedro Lourenço Avatar asked Apr 16 '17 02:04

Pedro Lourenço


People also ask

How do I add animations to actions in the navigation component?

The Navigation component lets you add both property and view animations to actions. To create your own animations, check out Animation resources. Navigation also includes several default animations to get you started. To add animations to an action, do the following: In the Navigation editor, click on the action where the animation should occur.

How do I add transition animations in navgraph?

To add the transition animations, in your NavGraph, click on an Action which you want to animate its transition. On your right, you will see a pane that has a section for adding animations:

How do I use shared elements with animation transitions?

Note: When using shared elements transitions, you should not use the Animation Framework ( enterAnim, exitAnim, and so on from the previous section). Instead, you should be using only the Transition Framework for setting your enter and exit transitions. Shared elements are supplied programmatically rather than through your navigation XML file.

What is transition framework in Android?

Android's transition framework allows you to animate all kinds of motion in your UI by simply providing the starting layout and the ending layout.


1 Answers

It's not possible to exclude components form overridePendingTransition() API. Instead, you have to move to Transitions API. Particularly, this is Slide transition animation, where you exclude your bottom navigation view.

Transition slide = new Slide(Gravity.RIGHT);
slide.excludeTarget(bottomNavigationView, true);
getWindow().setEnterTransition(slide);

See detailed implementation here.

You can see support transition package which backports Transitions API functionality upto API 14. But I couldn't find Slide transition in the classes list. Otherwise you can use TransitionEverywhere.

like image 68
azizbekian Avatar answered Oct 07 '22 00:10

azizbekian