SlideShare a Scribd company logo
1 of 41
Download to read offline
SCREEN TRANSITIONS IN
ANDROID
GO FROM A TO B IN STYLE
Created by fromAndrei Diaconu Android Iasi
ME
CODE ON GITHUB
https://github.com/andreidiaconu/transitions-animate-demo
Presentation (with working video) at https://andreidiaconu.github.io/transitions-animate-demo
bit.ly/screen-anim
WHAT IS A SCREEN TRANSITION?
 
WHAT ARE WE DOING TODAY?
8 Stages
STAGE 1 - DEFAULT ANIMATION
INITIAL SETUP
ACTIVITY A
grid.setOnItemClickListener(
  DetailsActivity1.start(GridActivity1.this, imageUrl);
)
ACTIVITY B
static void start(...,String imageUrl){
    intent = new Intent(...);
}
    
void onCreate(){
    Picasso
      .with(this)
      .load(imageUrl)
      .into(imageView);
}
 
STAGE 2 - MEASURING
Measure view in A
Send position to B
Resize the image in B
SEND POSITION
ACTIVITY A
void onItemClick(){
    DetailsActivity2.start(GridActivity2.this, imageUrl, view);
}
ACTIVITY B
static void start(..., View initialView){
    ...
    
    initialView.getGlobalVisibleRect(initialPosition);
    intent.putExtra("initialPosition", initialPosition);
    startActivity(intent);
}
 
STAGE 3 - NO DEFAULTS
Make B transparent
No default animations
Plan the animation
REMOVE DEFAULTS
STYLES.XML
<style name="AppTheme.Transparent">
</style>
  <item name="android:windowBackground">rtransparent</item>
  <item name="android:windowIsTranslucent">true</item>
STARTING ACTIVITY
from.overridePendingTransition(0,0);
RUN ONLY ONCE
void onCreate() {
    if (savedInstanceState==null){
        runAnimations();
    } 
}
 
STAGE 4 - START POSITION
Use translate and scale
Initial position for all views
WAIT FOR MEASUREMENTS
runAnimations(){
    imageView
        .getViewTreeObserver()
        .addOnPreDrawListener(
            boolean onPreDraw() {
                actuallyRunAnimations();
                removeOnPreDrawListener(this);
                return false;
            });
}
SET INITIAL POSITION
void actuallyRunAnimations(){
    Rect initialPosition = getIntent().getParcelableExtra(...);
    imageView.getGlobalVisibleRect(endPosition);
    //use initialPosition, endPosition
    imageView.setScaleY(...);
    imageView.setScaleX(...);
    imageView.setTranslationY(...);
    imageView.setTranslationX(...);
}
 
STAGE 5 - ANIMATE!
Animate image to final position
Fade background in
Bring other views from the sides
ANIMATE THINGS BACK TO NORMAL
imageView.animate()
        .scaleX(1)
        .scaleY(1)
        .translationX(0)
        .translationY(0)
        .setListener(
            void onAnimationEnd() {
                actionbar.animate()
                        .translationY(0)
                        .start();
            }
        ).start();
 
STAGE 6 - REVERSE
Override closing B
Animate everyhitng in reverse
Close B when on animation end
PREVENT FINISH()
@Override
public void finish() {
    if (canAnimateBack)
        runAnimationsBackwards();
    else
        super.finish();
}
DELAY FINISH()
imageView.animate()
    .scaleX(...)
    .scaleY(...)
    .translationX(...)
    .translationY(...)
    .setListener(
        void onAnimationEnd() {
            DetailsActivity6.super.finish();
            overridePendingTransition(0, 0);
        }
    ).start();
 
STAGE 7 - LOLLIPOP
Drop everything
Android 5 Screen Transitions
Define shared elements
STYLES.XML
<style name="AppTheme.Transitions">
    <item name = "windowActivityTransitions" >true</item>
</style>
LAYOUT B
<ImageView
    ...
    android:transitionName="shared_image"
    />
INTENT BUNDLE
ActivityOptionsCompat
    .makeSceneTransitionAnimation(from, initialView, "shared_image")
    .toBundle();
 
STAGE 8 - MAGIC
Content exit transition for A
Content enter transition for B
Detaults for exiting B and reentering A
EXIT + ENTER CONTENT TRANSITIONS
ACTIVTY A
getWindow().setExitTransition(new Explode());
ACTIVTY B
getWindow().setEnterTransition(new Slide());
 
COMPARISON
 
CODE ON GITHUB
https://github.com/andreidiaconu/transitions-animate-demo
Presentation (with working video) at https://andreidiaconu.github.io/transitions-animate-demo
bit.ly/screen-anim
THANK YOU!
QUESTIONS?
bit.ly/screen-anim

More Related Content

Similar to Material design screen transitions in android

Develop Denver 2014: Building Physical Video Games
Develop Denver 2014: Building Physical Video GamesDevelop Denver 2014: Building Physical Video Games
Develop Denver 2014: Building Physical Video Gamescacheflowe
 
Building a camera in a program | Computer Graphics
Building a camera in a program | Computer GraphicsBuilding a camera in a program | Computer Graphics
Building a camera in a program | Computer GraphicsAravindhan Anbazhagan
 
The not so short
The not so shortThe not so short
The not so shortAXM
 
Leaving Interface Builder Behind
Leaving Interface Builder BehindLeaving Interface Builder Behind
Leaving Interface Builder BehindJohn Wilker
 
Game development via_sprite_kit
Game development via_sprite_kitGame development via_sprite_kit
Game development via_sprite_kitBuşra Deniz, CSM
 
Building a Native Camera Access Library - Part I.pdf
Building a Native Camera Access Library - Part I.pdfBuilding a Native Camera Access Library - Part I.pdf
Building a Native Camera Access Library - Part I.pdfShaiAlmog1
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded GraphicsAdil Jafri
 
Standford 2015 week7: 1. Unwind Segues, Alerts, Timers, View Animation 2. Dyn...
Standford 2015 week7: 1. Unwind Segues, Alerts, Timers, View Animation 2. Dyn...Standford 2015 week7: 1. Unwind Segues, Alerts, Timers, View Animation 2. Dyn...
Standford 2015 week7: 1. Unwind Segues, Alerts, Timers, View Animation 2. Dyn...彼得潘 Pan
 
How to autorun graphic application
How to autorun graphic applicationHow to autorun graphic application
How to autorun graphic applicationytanno
 
Creating an Uber Clone - Part XXIV - Transcript.pdf
Creating an Uber Clone - Part XXIV - Transcript.pdfCreating an Uber Clone - Part XXIV - Transcript.pdf
Creating an Uber Clone - Part XXIV - Transcript.pdfShaiAlmog1
 
Lviv MD Day 2015 Костянтин Бичков "iOS Autolayouts – це добре!"
Lviv MD Day 2015 Костянтин Бичков "iOS Autolayouts – це добре!"Lviv MD Day 2015 Костянтин Бичков "iOS Autolayouts – це добре!"
Lviv MD Day 2015 Костянтин Бичков "iOS Autolayouts – це добре!"Lviv Startup Club
 
UIViewControllerのコーナーケース
UIViewControllerのコーナーケースUIViewControllerのコーナーケース
UIViewControllerのコーナーケースKatsumi Kishikawa
 

Similar to Material design screen transitions in android (20)

Develop Denver 2014: Building Physical Video Games
Develop Denver 2014: Building Physical Video GamesDevelop Denver 2014: Building Physical Video Games
Develop Denver 2014: Building Physical Video Games
 
662305 LAB13
662305 LAB13662305 LAB13
662305 LAB13
 
Building a camera in a program | Computer Graphics
Building a camera in a program | Computer GraphicsBuilding a camera in a program | Computer Graphics
Building a camera in a program | Computer Graphics
 
The not so short
The not so shortThe not so short
The not so short
 
Leaving Interface Builder Behind
Leaving Interface Builder BehindLeaving Interface Builder Behind
Leaving Interface Builder Behind
 
004
004004
004
 
iphonedevcon 2010: Cooking with iAd
iphonedevcon 2010:  Cooking with iAd iphonedevcon 2010:  Cooking with iAd
iphonedevcon 2010: Cooking with iAd
 
QXCameraKit
QXCameraKitQXCameraKit
QXCameraKit
 
Game development via_sprite_kit
Game development via_sprite_kitGame development via_sprite_kit
Game development via_sprite_kit
 
Dip iit workshop
Dip iit workshopDip iit workshop
Dip iit workshop
 
Building a Native Camera Access Library - Part I.pdf
Building a Native Camera Access Library - Part I.pdfBuilding a Native Camera Access Library - Part I.pdf
Building a Native Camera Access Library - Part I.pdf
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded Graphics
 
Standford 2015 week7: 1. Unwind Segues, Alerts, Timers, View Animation 2. Dyn...
Standford 2015 week7: 1. Unwind Segues, Alerts, Timers, View Animation 2. Dyn...Standford 2015 week7: 1. Unwind Segues, Alerts, Timers, View Animation 2. Dyn...
Standford 2015 week7: 1. Unwind Segues, Alerts, Timers, View Animation 2. Dyn...
 
Basics cocos2d
Basics cocos2dBasics cocos2d
Basics cocos2d
 
How to autorun graphic application
How to autorun graphic applicationHow to autorun graphic application
How to autorun graphic application
 
Creating an Uber Clone - Part XXIV - Transcript.pdf
Creating an Uber Clone - Part XXIV - Transcript.pdfCreating an Uber Clone - Part XXIV - Transcript.pdf
Creating an Uber Clone - Part XXIV - Transcript.pdf
 
Lviv MD Day 2015 Костянтин Бичков "iOS Autolayouts – це добре!"
Lviv MD Day 2015 Костянтин Бичков "iOS Autolayouts – це добре!"Lviv MD Day 2015 Костянтин Бичков "iOS Autolayouts – це добре!"
Lviv MD Day 2015 Костянтин Бичков "iOS Autolayouts – це добре!"
 
UIViewControllerのコーナーケース
UIViewControllerのコーナーケースUIViewControllerのコーナーケース
UIViewControllerのコーナーケース
 
iOS Training Session-3
iOS Training Session-3iOS Training Session-3
iOS Training Session-3
 
Fog effect opengl project
Fog effect opengl projectFog effect opengl project
Fog effect opengl project
 

More from Codecamp Romania

Cezar chitac the edge of experience
Cezar chitac   the edge of experienceCezar chitac   the edge of experience
Cezar chitac the edge of experienceCodecamp Romania
 
Business analysis techniques exercise your 6-pack
Business analysis techniques   exercise your 6-packBusiness analysis techniques   exercise your 6-pack
Business analysis techniques exercise your 6-packCodecamp Romania
 
Bpm company code camp - configuration or coding with pega
Bpm company   code camp - configuration or coding with pegaBpm company   code camp - configuration or coding with pega
Bpm company code camp - configuration or coding with pegaCodecamp Romania
 
Andrei prisacaru takingtheunitteststothedatabase
Andrei prisacaru takingtheunitteststothedatabaseAndrei prisacaru takingtheunitteststothedatabase
Andrei prisacaru takingtheunitteststothedatabaseCodecamp Romania
 
2015 dan ardelean develop for windows 10
2015 dan ardelean   develop for windows 10 2015 dan ardelean   develop for windows 10
2015 dan ardelean develop for windows 10 Codecamp Romania
 
The case for continuous delivery
The case for continuous deliveryThe case for continuous delivery
The case for continuous deliveryCodecamp Romania
 
Stefan stolniceanu spritekit, 2 d or not 2d
Stefan stolniceanu   spritekit, 2 d or not 2dStefan stolniceanu   spritekit, 2 d or not 2d
Stefan stolniceanu spritekit, 2 d or not 2dCodecamp Romania
 
Sizing epics tales from an agile kingdom
Sizing epics   tales from an agile kingdomSizing epics   tales from an agile kingdom
Sizing epics tales from an agile kingdomCodecamp Romania
 
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...
Raluca butnaru corina cilibiu   the unknown universe of a product and the cer...Raluca butnaru corina cilibiu   the unknown universe of a product and the cer...
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...Codecamp Romania
 
Parallel & async processing using tpl dataflow
Parallel & async processing using tpl dataflowParallel & async processing using tpl dataflow
Parallel & async processing using tpl dataflowCodecamp Romania
 
Material design screen transitions in android
Material design screen transitions in androidMaterial design screen transitions in android
Material design screen transitions in androidCodecamp Romania
 
Kickstart your own freelancing career
Kickstart your own freelancing careerKickstart your own freelancing career
Kickstart your own freelancing careerCodecamp Romania
 
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkit
Ionut grecu   the soft stuff is the hard stuff. the agile soft skills toolkitIonut grecu   the soft stuff is the hard stuff. the agile soft skills toolkit
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkitCodecamp Romania
 
Diana antohi me against myself or how to fail and move forward
Diana antohi   me against myself  or how to fail  and move forwardDiana antohi   me against myself  or how to fail  and move forward
Diana antohi me against myself or how to fail and move forwardCodecamp Romania
 

More from Codecamp Romania (20)

Cezar chitac the edge of experience
Cezar chitac   the edge of experienceCezar chitac   the edge of experience
Cezar chitac the edge of experience
 
Cloud powered search
Cloud powered searchCloud powered search
Cloud powered search
 
Ccp
CcpCcp
Ccp
 
Business analysis techniques exercise your 6-pack
Business analysis techniques   exercise your 6-packBusiness analysis techniques   exercise your 6-pack
Business analysis techniques exercise your 6-pack
 
Bpm company code camp - configuration or coding with pega
Bpm company   code camp - configuration or coding with pegaBpm company   code camp - configuration or coding with pega
Bpm company code camp - configuration or coding with pega
 
Andrei prisacaru takingtheunitteststothedatabase
Andrei prisacaru takingtheunitteststothedatabaseAndrei prisacaru takingtheunitteststothedatabase
Andrei prisacaru takingtheunitteststothedatabase
 
Agility and life
Agility and lifeAgility and life
Agility and life
 
2015 dan ardelean develop for windows 10
2015 dan ardelean   develop for windows 10 2015 dan ardelean   develop for windows 10
2015 dan ardelean develop for windows 10
 
The bigrewrite
The bigrewriteThe bigrewrite
The bigrewrite
 
The case for continuous delivery
The case for continuous deliveryThe case for continuous delivery
The case for continuous delivery
 
Stefan stolniceanu spritekit, 2 d or not 2d
Stefan stolniceanu   spritekit, 2 d or not 2dStefan stolniceanu   spritekit, 2 d or not 2d
Stefan stolniceanu spritekit, 2 d or not 2d
 
Sizing epics tales from an agile kingdom
Sizing epics   tales from an agile kingdomSizing epics   tales from an agile kingdom
Sizing epics tales from an agile kingdom
 
Scale net apps in aws
Scale net apps in awsScale net apps in aws
Scale net apps in aws
 
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...
Raluca butnaru corina cilibiu   the unknown universe of a product and the cer...Raluca butnaru corina cilibiu   the unknown universe of a product and the cer...
Raluca butnaru corina cilibiu the unknown universe of a product and the cer...
 
Parallel & async processing using tpl dataflow
Parallel & async processing using tpl dataflowParallel & async processing using tpl dataflow
Parallel & async processing using tpl dataflow
 
Material design screen transitions in android
Material design screen transitions in androidMaterial design screen transitions in android
Material design screen transitions in android
 
Kickstart your own freelancing career
Kickstart your own freelancing careerKickstart your own freelancing career
Kickstart your own freelancing career
 
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkit
Ionut grecu   the soft stuff is the hard stuff. the agile soft skills toolkitIonut grecu   the soft stuff is the hard stuff. the agile soft skills toolkit
Ionut grecu the soft stuff is the hard stuff. the agile soft skills toolkit
 
Ecma6 in the wild
Ecma6 in the wildEcma6 in the wild
Ecma6 in the wild
 
Diana antohi me against myself or how to fail and move forward
Diana antohi   me against myself  or how to fail  and move forwardDiana antohi   me against myself  or how to fail  and move forward
Diana antohi me against myself or how to fail and move forward
 

Material design screen transitions in android