Here at SWARM, a design and app development company based in New York, we are focused on exploring new ways to improve Android apps. Here's a great tip on how to add some sizzle to your app, simply by using the transition and animation support built into the fragment framework.

Transitions

To use one of the built-in Transitions, use the setTranstion() method:

getSupportFragmentManager()
.beginTransaction()
.setTransition( FragmentTransaction.TRANSIT_FRAGMENT_OPEN )
.show( m_topFragment )
.commit()

 

Custom Animations

You can also customize the animation by using the setCustomAnimations() method:

getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations( R.anim.slide_in_left, 0, 0, R.anim.slide_out_left)
.show( m_topFragment )
.commit()
 

Multiple Animations

Finally, It's also possible to kick-off multiple fragment animations in a single transaction. This allows for a pretty cool effect where one fragment is sliding up and the other slides down at the same time:

getSupportFragmentManager()
.beginTransaction()
.setCustomAnimations( R.anim.abc_slide_in_top, R.anim.abc_slide_out_top ) // Top Fragment Animation
.show( m_topFragment )
.setCustomAnimations( R.anim.abc_slide_in_bottom, R.anim.abc_slide_out_bottom ) // Bottom Fragment Animation
.show( m_bottomFragment )
.commit()

Checkout the code for this sample on Github: https://github.com/swarmnyc/AndroidFragmentAnimations. Look forward to your thoughts.

Recommended Posts

3
August

Electric car highways πŸ‡¦πŸ‡Ί, full-body VR, and 3D-printed... Earables? πŸ‘‚

This week we're talking about full-body VR wearables, human organ factories in New Hampshire, the largest electric vehic...

Read More >

27
July

If you care about the environment, we've got some wins for you πŸ‘

This week we're talking about robotic eels tracking water pollution, building DNA from scratchπŸ‘¨‍πŸ”¬, the first float...

Read More >

20
July

Talk to the hand βœ‹, my smart-wearable-glove hand 😎

This week we're talking about smart gloves that translate sign language! πŸ™‹, Moon-mining in 2020 πŸŒ•, the top programming...

Read More >

Let's solve digital.