安卓(Android) 怎么在容器中开始展开动画(Animation)

2019年10月15日20:29:55安卓(Android) 怎么在容器中开始展开动画(Animation)已关闭评论 285 1151字阅读3分50秒

1.简介

安卓(Android) 怎么在容器中开始展开动画(Animation)?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */
import android.graphics.Point;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.OvershootInterpolator;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;

public class Main {

  public static void startTranslateAnimationExpand(final View view, Point start, final Point end, int offset,
      int duration) {
    Animation animation = new TranslateAnimation(start.x - end.x, 0, start.y - end.y, 0);
    Animation s_aniAnimation = new ScaleAnimation(0, 1, 0, 1, Animation.RELATIVE_TO_SELF, 0.5f,
        Animation.RELATIVE_TO_SELF, 0.5f);
    Animation alpha = new AlphaAnimation(0, 1);
    AnimationSet as = new AnimationSet(true);
    as.addAnimation(s_aniAnimation);
    as.addAnimation(animation);
    as.addAnimation(alpha);
    as.setDuration(duration);
    as.setFillAfter(true);
    as.setStartOffset(offset);
    as.setInterpolator(new OvershootInterpolator(2F));
    view.startAnimation(as);
    
  }

  public static void enableView(View view) {
    view.setVisibility(0);
    view.setFocusable(true);
    view.setClickable(true);
    view.setAlpha(1);
  }
}

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