Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 31st, 2012  |  syntax: None  |  size: 2.04 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Playing DISAPPEARING and APPEARING layout animation
  2. public void onClick(View v) {
  3.  
  4.             if (componentOneVisible) {
  5.                 componentOne.setVisibility(View.GONE);
  6.                 componentTwo.setVisibility(View.VISIBLE);
  7.             } else {
  8.  
  9.                 componentTwo.setVisibility(View.GONE);
  10.                 componentOne.setVisibility(View.VISIBLE);
  11.             }
  12.  
  13.             componentOneVisible = !componentOneVisible;
  14.         }
  15.        
  16. final ObjectAnimator testIn = ObjectAnimator.ofPropertyValuesHolder(
  17.             componentContainer,
  18.             PropertyValuesHolder.ofFloat("scaleX", 0, 1f),
  19.             PropertyValuesHolder.ofFloat("scaleY", 0, 1f),
  20.             PropertyValuesHolder.ofFloat("alpha", 0f, 1f));
  21.  
  22.     testIn.addListener(new AnimatorListenerAdapter() {
  23.         public void onAnimationEnd(Animator anim) {
  24.             View view = (View) ((ObjectAnimator) anim).getTarget();
  25.             view.setScaleX(1f);
  26.             view.setScaleY(1f);
  27.             view.setAlpha(1f);
  28.         }
  29.     });
  30.  
  31.     testIn.setDuration(3000);
  32.  
  33.  
  34.     final ObjectAnimator testOut = ObjectAnimator.ofPropertyValuesHolder(
  35.             componentContainer,
  36.             PropertyValuesHolder.ofFloat("scaleX", 1f, 0),
  37.             PropertyValuesHolder.ofFloat("scaleY", 1f, 0),
  38.             PropertyValuesHolder.ofFloat("alpha", 1, 0f));
  39.  
  40.  
  41.     testOut.setDuration(3000);
  42.  
  43.     testOut.addListener(new AnimatorListenerAdapter() {
  44.         public void onAnimationEnd(Animator anim) {
  45.             View view = (View) ((ObjectAnimator) anim).getTarget();
  46.             view.setScaleX(0f);
  47.             view.setScaleY(0f);
  48.             view.setAlpha(0f);
  49.         }
  50.     });
  51.  
  52.  
  53.  
  54.  
  55.     mTransitioner.setAnimator(LayoutTransition.APPEARING, testIn);
  56.     mTransitioner.setAnimator(LayoutTransition.DISAPPEARING, testOut);
  57.  
  58.     mTransitioner.setDuration(5000);
  59.  
  60.     mTransitioner.setDuration(LayoutTransition.APPEARING, 3000);
  61.     mTransitioner.setDuration(LayoutTransition.DISAPPEARING, 3000);
  62.        
  63. mTransitioner = new LayoutTransition();
  64.     componentContainer.setLayoutTransition(mTransitioner);