Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Screen Transitions in Android

Screen Transitions in Android

Go from screen A to screen B in style. Let's learn together how to animate the transition between the pictures-grid-screen and the picture-details-screen, both on Android 5 and below.

Presented at Codecamp Iasi Spring 2015

Andrei Diaconu

November 27, 2016

Transcript

40 slides
  1. SCREEN TRANSITIONS IN ANDROID GO FROM A TO B IN

    STYLE Created by from Andrei Diaconu Android Iasi
  2. ME

  3. 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); }
  4. 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); }
  5. WAIT FOR MEASUREMENTS runAnimations(){ imageView .getViewTreeObserver() .addOnPreDrawListener( boolean onPreDraw() {

    actuallyRunAnimations(); removeOnPreDrawListener(this); return false; }); }
  6. SET INITIAL POSITION void actuallyRunAnimations(){ Rect initialPosition = getIntent().getParcelableExtra(...); imageView.getGlobalVisibleRect(endPosition);

    //use initialPosition, endPosition imageView.setScaleY(...); imageView.setScaleX(...); imageView.setTranslationY(...); imageView.setTranslationX(...); }
  7. STAGE 5 - ANIMATE! Animate image to nal position Fade

    background in Bring other views from the sides
  8. ANIMATE THINGS BACK TO NORMAL imageView.animate() .scaleX(1) .scaleY(1) .translationX(0) .translationY(0)

    .setListener( void onAnimationEnd() { actionbar.animate() .translationY(0) .start(); } ).start();
  9. STAGE 6 - REVERSE Override closing B Animate everyhitng in

    reverse Close B when on animation end
  10. STAGE 8 - MAGIC Content exit transition for A Content

    enter transition for B Detaults for exiting B and reentering A

More Decks by Andrei Diaconu

Other Decks in Programming