安卓(Android) 怎么实现水平隐藏视图(View)

2019年10月14日21:49:53安卓(Android) 怎么实现水平隐藏视图(View)已关闭评论 338 960字阅读3分12秒

1.简介

安卓(Android) 怎么实现水平隐藏视图(View)?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */

import android.animation.Animator;
import android.support.v4.view.animation.FastOutSlowInInterpolator;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.view.animation.Interpolator;

public class Main {
  private static final Interpolator FAST_OUT_SLOW_IN_INTERPOLATOR = new FastOutSlowInInterpolator();

  public static void hideViewX(final View view, boolean animToRight) {
    ViewPropertyAnimator animator = view.animate().translationX((animToRight) ? view.getWidth() : view.getWidth() * -1)
        .setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR).setDuration(200);

    animator.setListener(new Animator.AnimatorListener() {
      @Override
      public void onAnimationStart(Animator animator) {
      }

      @Override
      public void onAnimationEnd(Animator animator) {
        view.setVisibility(View.GONE);
        view.setX(0);
      }

      @Override
      public void onAnimationCancel(Animator animator) {
      }

      @Override
      public void onAnimationRepeat(Animator animator) {
      }
    });
    animator.start();
  }
}

 
继续阅读
编程十万个怎么办