Ejemplo n.º 1
0
 // Same animation that FloatingActionButton.Behavior uses to show the FAB when the AppBarLayout
 // enters
 private void animateIn(FloatingActionButton button) {
   button.setVisibility(View.VISIBLE);
   Animation anim = AnimationUtils.loadAnimation(button.getContext(), R.anim.abc_slide_in_bottom);
   anim.setDuration(600L);
   anim.setInterpolator(INTERPOLATOR);
   button.startAnimation(anim);
 }
  // Same animation that FloatingActionButton.Behavior uses to hide the FAB when the AppBarLayout
  // exits
  private void animateOut(final FloatingActionButton button) {
    if (Build.VERSION.SDK_INT >= 14) {
      ViewCompat.animate(button)
          .scaleX(0.0F)
          .scaleY(0.0F)
          .alpha(0.0F)
          .setInterpolator(INTERPOLATOR)
          .withLayer()
          .setListener(
              new ViewPropertyAnimatorListener() {
                public void onAnimationStart(View view) {
                  ScrollAwareFABBehavior.this.mIsAnimatingOut = true;
                }

                public void onAnimationCancel(View view) {
                  ScrollAwareFABBehavior.this.mIsAnimatingOut = false;
                }

                public void onAnimationEnd(View view) {
                  ScrollAwareFABBehavior.this.mIsAnimatingOut = false;
                  view.setVisibility(View.GONE);
                }
              })
          .start();
    } else {
      Animation anim = AnimationUtils.loadAnimation(button.getContext(), android.R.anim.fade_out);
      anim.setInterpolator(INTERPOLATOR);
      anim.setDuration(200L);
      anim.setAnimationListener(
          new Animation.AnimationListener() {
            public void onAnimationStart(Animation animation) {
              ScrollAwareFABBehavior.this.mIsAnimatingOut = true;
            }

            public void onAnimationEnd(Animation animation) {
              ScrollAwareFABBehavior.this.mIsAnimatingOut = false;
              button.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationRepeat(final Animation animation) {}
          });
      button.startAnimation(anim);
    }
  }
 // Same animation that FloatingActionButton.Behavior uses to show the FAB when the AppBarLayout
 // enters
 private void animateIn(FloatingActionButton button) {
   button.setVisibility(View.VISIBLE);
   if (Build.VERSION.SDK_INT >= 14) {
     ViewCompat.animate(button)
         .scaleX(1.0F)
         .scaleY(1.0F)
         .alpha(1.0F)
         .setInterpolator(INTERPOLATOR)
         .withLayer()
         .setListener(null)
         .start();
   } else {
     Animation anim = AnimationUtils.loadAnimation(button.getContext(), android.R.anim.fade_in);
     anim.setDuration(200L);
     anim.setInterpolator(INTERPOLATOR);
     button.startAnimation(anim);
   }
 }
Ejemplo n.º 4
0
  // Same animation that FloatingActionButton.Behavior uses to hide the FAB when the AppBarLayout
  // exits
  private void animateOut(final FloatingActionButton button) {
    Animation anim = AnimationUtils.loadAnimation(button.getContext(), R.anim.abc_slide_out_bottom);
    anim.setInterpolator(INTERPOLATOR);
    anim.setDuration(600L);
    anim.setAnimationListener(
        new Animation.AnimationListener() {
          public void onAnimationStart(Animation animation) {
            ScrollAwareFABBehavior.this.mIsAnimatingOut = true;
          }

          public void onAnimationEnd(Animation animation) {
            ScrollAwareFABBehavior.this.mIsAnimatingOut = false;
            button.setVisibility(View.GONE);
          }

          @Override
          public void onAnimationRepeat(final Animation animation) {}
        });
    button.startAnimation(anim);
  }