Android 애니메이션 도구 류 의 패키지 실전 기록
최근 에 구성 요소 화 된 프레임 워 크 의 패 키 징 을 만 들 고 있 습 니 다.지금 은 자주 사용 하 는 도구 류 의 패 키 징 을 개 발 했 습 니 다.갑자기 애니메이션 을 만 들 지 않 은 것 같다 는 것 을 깨 닫 고 개발 에 착 수 했 습 니 다.
사고의 방향
애니메이션 을 하려 면 속성 애니메이션 의 도구 류 의 패 키 징 을 해 야 합 니 다.보충 애니메이션 과 프레임 애니메이션 은 목표 애니메이션 주제 의 실제 속성 을 바 꿀 수 없 기 때문에 안 드 로 이 드 의 개발 에서 이 두 애니메이션 프레임 워 크 로 개발 하 는 사람 이 점점 줄 어 들 었 고 속성 애니메이션 은 개발 과정 에서 상대 적 으로 광범 위 하 게 사용 되 었 습 니 다.그래서 이번 도구 류 의 패 키 징 은 속성 애니메이션 에 만 패 키 징 됩 니 다.
속성 애니메이션 에 대응 하 는 유형 은 ObjectAnimator 라 고 하 는데 주로 이런 유형 으로 애니메이션 의 기본 설정 을 실현 하 는 것 입 니 다.구체 적 인 사용 방식 은 쓰 지 않 겠 습 니 다.관심 이 있 는 친구 들 은 속성 애니메이션 에 관 한 지식 을 스스로 배 울 수 있 습 니 다.
패 키 징 속성 애니메이션 도구 류 는 속성 애니메이션 의 조합 재생 수 요 를 고려 해 야 하고 속성 애니메이션 의 조합 재생 은 약 세 가지 방식 이 있다.
1.애 니 메 이 터 셋 빌 더 를 조합 해서 재생
Animator Set.Builder 는 애니메이션 도구 류 로 Animator Set 에 애니메이션 을 추가 하고 각종 애니메이션 간 의 관 계 를 설정 하 는 데 편리 합 니 다....에 있다 Animator Set.Builder 에 서 는 after(long),after(Animator),before(Animator),with(Animator)등 네 가지 방법 을 밝 혔 다.
AnimatorSet set=new AnimatorSet();
set.play(anim1).before(anim2).with(anim3).after(anim4);우 리 는 그 가 먼저 after 를 실행 한 다음 에 play 와 with 가 동시에 실행 하고 마지막 에 실행 한 before 라 는 것 을 알 았 다.그래서 여러분 은 이 순 서 를 기억 하 세 요.아무리 써 도 이 집행 순서 입 니 다.2.Animator Set 의 play Sequentially 사용 하기
API
AnimatorSet bouncer = new AnimatorSet();
ObjectAnimator objectAnimatorA = ObjectAnimator.ofFloat(btnProperty, PropertyConstant.PROPERTY_TRANSLATION_X, 0f, 300f);
ObjectAnimator objectAnimatorB = ObjectAnimator.ofFloat(btnProperty, PropertyConstant.PROPERTY_TRANSLATION_Y, 0f, 300f);
ObjectAnimator objectAnimatorC = ObjectAnimator.ofFloat(btnProperty, PropertyConstant.PROPERTY_ROTATION, 0f, 360f);
bouncer.playSequentially(objectAnimatorA, objectAnimatorB, objectAnimatorC);
bouncer.setDuration(6000);
bouncer.start();3.애 니 메 이 터 셋 의 paly Together 사용 하기API
AnimatorSet bouncer = new AnimatorSet();
ObjectAnimator objectAnimatorA = ObjectAnimator.ofFloat(btnProperty, PropertyConstant.PROPERTY_TRANSLATION_X, 0f, 300f);
ObjectAnimator objectAnimatorB = ObjectAnimator.ofFloat(btnProperty, PropertyConstant.PROPERTY_TRANSLATION_Y, 0f, 300f);
ObjectAnimator objectAnimatorC = ObjectAnimator.ofFloat(btnProperty, PropertyConstant.PROPERTY_ROTATION, 0f, 360f);
bouncer.playSequentially(objectAnimatorA, objectAnimatorB, objectAnimatorC);
bouncer.setDuration(6000);
bouncer.start();이상 의 지식 포 인 트 를 파악 한 후에 제 생각 은 마지막 으로 집행 방식 에 대한 포장 입 니 다.이른바 집행 방식 은 play,play Sequentially 와 play Together 세 가지 방법 을 어떻게 정상적으로 호출 하 는 지 하 는 것 입 니 다.여 기 는 합 리 적 인 포장 이 필요 합 니 다.그리고 감청 인터페이스 에 대한 패키지 입 니 다.Object Animator 마다 세 개의 인터페이스 가 있 습 니 다.
Animator.AnimatorListener 전체 애니메이션 수명 주기 에 대한 감청
anim.addListener(new Animator.AnimatorListener() {
 @Override
 public void onAnimationStart(Animator animator) {
 Toast.makeText(MainActivity.this, "start", Toast.LENGTH_LONG).show();
 }
 @Override
 public void onAnimationEnd(Animator animator) {
 Toast.makeText(MainActivity.this, "End", Toast.LENGTH_LONG).show();
 }
 @Override
 public void onAnimationCancel(Animator animator) {
 Toast.makeText(MainActivity.this, "Cancel", Toast.LENGTH_LONG).show();
 }
 @Override
 public void onAnimationRepeat(Animator animator) {
 Toast.makeText(MainActivity.this, "rapeat", Toast.LENGTH_LONG).show();
 }
 });
 anim.start();ValueAnimator.Animator UpdateListener 가 이 애니메이션 프레임 에 대한 감청
ValueAnimator vanim = ValueAnimator.ofInt(0,10,20);
 vanim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
 @Override
 public void onAnimationUpdate(ValueAnimator valueAnimator) {
 //     ValueAnimtor    Int i ,     Value  int  ,
                  
 int value = (int) valueAnimator.getAnimatedValue();
 }
 });Animator.Animator PauseListener 가 이 애니메이션 의 일시 정지 와 재생 에 대한 감청
new Animator.AnimatorPauseListener() {
 @Override
 public void onAnimationPause(Animator animator) {
 
 }
 @Override
 public void onAnimationResume(Animator animator) {
 }
 }제 초보적인 구상 은 건축 자 모델 의 체인 호출 모델 을 사용 하여 제 도구 류 를 디자인 하 는 것 입 니 다.만약 에 일반적인 기법 에 따라 전체 감청 인터페이스의 설정 은 재난 적일 것 입 니 다.모든 감청 인터페이스의 설정 이 혼 란 스 러 우 므 로 여기 서 처리 해 야 합 니 다.제 생각 은 SpringSecurity 의 체인 호출 디자인 을 배 우 는 것 입 니 다.각 유형의 감청 을 위해 자신의 종 류 를 설정 한 다음 에 도구 의 주 류 를 이 유형의 감청 인 터 페 이 스 를 호출 시 킨 다음 에 설정 이 끝 난 후에 이 감청 인터페이스 류 의 and()방법 을 통 해 도구 류 의 주 유형 으로 돌아 갑 니 다.그러면 체인 호출 할 때 시작 순서 가 있 고 혼 란 스 럽 게 실행 되 지 않 습 니 다.또한 감청 을 설정 하지 않 으 면감청 류 설정 을 호출 하지 않 아 도 주 클래스 의 실행 에 영향 을 주지 않 습 니 다.핵심 코드 를 캡 처 하고 Play 방법의 감청 인터페이스 설정 을 예 로 들 면:
/**
*      
**/
public static class AnimatorSetWrap{
 PlayAnimationListener playListener;
 public PlayAnimationListener toAddPlayListener(){
 playListener=new PlayAnimationListener(this);
 return playListener;
 }
 }
/**
 * Play     ObjectAnimator     
 */
 public static class PlayAnimationListener implements IAnimatorListener<PlayAnimationListener>{
 private Animator.AnimatorListener animatorListener;
 private ValueAnimator.AnimatorUpdateListener updateListener;
 private Animator.AnimatorPauseListener pauseListener;
 public AnimatorSetWrap animatorSetWrap;
 public PlayAnimationListener(AnimatorSetWrap animatorSetWrap){
 this.animatorSetWrap=animatorSetWrap;
 }
 @Override
 public PlayAnimationListener setAnimatorListener(Animator.AnimatorListener animatorListener) {
 this.animatorListener=animatorListener;
 return this;
 }
 @Override
 public PlayAnimationListener setUpdateListener(ValueAnimator.AnimatorUpdateListener animatorListener) {
 this.updateListener=animatorListener;
 return this;
 }
 @Override
 public PlayAnimationListener setPauseListener(Animator.AnimatorPauseListener animatorListener) {
 this.pauseListener=animatorListener;
 return this;
 }
 @Override
 public AnimatorSetWrap and(){
 return animatorSetWrap;
 }
 }
/**
 *            
 * @param <T>
 */
 interface IAnimatorListener<T>{
 /**
 *   AnimatorListener   
 * @param listener
 * @return
 */
 T setAnimatorListener(Animator.AnimatorListener listener);
 /**
 *   AnimatorUpdateListener   
 * @param listener
 * @return
 */
 T setUpdateListener(ValueAnimator.AnimatorUpdateListener listener);
 /**
 *   AnimatorPauseListener   
 * @param listener
 * @return
 */
 T setPauseListener(Animator.AnimatorPauseListener listener);
 /**
 *                
 * @return
 */
 AnimatorSetWrap and();
 }구체 적 인 사용 방법:
AnimatorUtil.AnimatorSetWrap animatorSetWrapDemo=new AnimatorSetWrap().toAddPlayListener().setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
 @Override
 public void onAnimationUpdate(ValueAnimator valueAnimator) {
 LogUtils.e("  :"+valueAnimator.getAnimatedValue());
 }
 }).and();이러한 체인 호출 을 통 해 and()방법 을 호출 하면 Animator SetWrap 도구 류 의 인 스 턴 스 로 돌아 가 고 나머지 는 다른 애니메이션 방법 을 계속 호출 하여 애니메이션 을 재생 할 수 있 습 니 다.코드
이렇게 많아
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.TimeInterpolator;
import android.animation.ValueAnimator;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.Size;
import android.view.View;
import android.view.animation.LinearInterpolator;
import java.util.ArrayList;
import java.util.List;
/**
 *      
 *@package com.dhcc.commonutils
 *@author jasoncool
 *@createDate 2018/11/20 16:16
 *@description
 **/
public class AnimatorUtils {
 public static final String ALPHA="Alpha";
 public static final String TRANSX="TranslationX";
 public static final String TRANSY="TranslationY";
 public static final String SCALEX="ScaleX";
 public static final String SCALEY="ScaleY";
 public static final String ROTATION="Rotation";
 public static final String ROTATIONX="RotationX";
 public static final String ROTATIONY="RotationY";
 /**
 *    TimeInterpolator,    ,    
 */
 private static final TimeInterpolator sDefaultInterpolator =
 new LinearInterpolator();
 public static AnimatorSetWrap createAnimator() {
 return new AnimatorSetWrap();
 }
 /**
 * @param interpolator    TimeInterpolator
 * @return
 */
 public static AnimatorSetWrap createAnimator(TimeInterpolator interpolator) {
 return new AnimatorSetWrap(interpolator);
 }
 /**
 *       
 *           AnimatorSet ,     new   。
 *
 *             ,play,before,with,after。
 *                  animator ,
 *            ,       ,  ,  ,     。
 *            after,   play with    ,     before。
 *           ,     ,        。
 *
 */
 public static class AnimatorSetWrap{
 private View mView;
 /**
 *          ,           
 */
 private TimeInterpolator mTimeInterpolator;
 /**
 *   play             
 */
 boolean mIsPlaying=false;
 /**
 *          
 */
 private AnimatorSet mAnimatorSet;
 /**
 *           
 */
 private AnimatorSet.Builder mAnimatorBuilder;
 /**
 *       
 */
 private int mDuration=1000;
 /**
 * play     
 */
 PlayAnimationListener playListener;
 /**
 * before     
 */
 BeforeAnimationListener beforeListener;
 /**
 * with     
 */
 WithAnimationListener withListener;
 /**
 * after     
 */
 AfterAnimationListener afterListener;
 /**
 * then     
 */
 ThenAnimationListener thenListener;
 /**
 *                     
 */
 List<Animator> mAnimatorList;
 /**
 *        then  
 */
 boolean mHasInitThenAnim=false;
 private AnimatorSetWrap(){
 this(sDefaultInterpolator);
 }
 /**
 *     
 *      
 * 1.          mTimeInterpolator
 * 2.       Set mAnimatorSet
 * 3.               mAnimatorList
 * @param interpolator
 */
 private AnimatorSetWrap(TimeInterpolator interpolator) {
 mTimeInterpolator = interpolator;
 mAnimatorSet = new AnimatorSet();
 mAnimatorList=new ArrayList<>(16);
 }
 /**
 * Play         
 *      play         
 * @return
 */
 public PlayAnimationListener toAddPlayListener(){
 playListener=new PlayAnimationListener(this);
 return playListener;
 }
 /**
 * Before         
 *      Before         
 * @return
 */
 public BeforeAnimationListener toAddBeforeListener(){
 beforeListener=new BeforeAnimationListener(this);
 return beforeListener;
 }
 /**
 * With         
 *      With         
 * @return
 */
 public WithAnimationListener toAddWithListener(){
 withListener=new WithAnimationListener(this);
 return withListener;
 }
 /**
 * After         
 *      After         
 * @return
 */
 public AfterAnimationListener toAddAfterListener(){
 afterListener=new AfterAnimationListener(this);
 return afterListener;
 }
 /**
 *                  
 *    Then      
 * @return
 */
 public ThenAnimationListener toAddThenListener(){
 thenListener=new ThenAnimationListener(this);
 return thenListener;
 }
 /**
 *                 
 *         Animator   Animator   mAnimatorList   
 * @param view        View
 * @param animName     
 * @param interpolator                 
 * @param repeatCount     
 * @param duration     
 * @param values       
 * @return
 */
 public AnimatorSetWrap then(View view, String animName, @Nullable TimeInterpolator interpolator, @Size(min = 0,max=Integer.MAX_VALUE) int repeatCount, @Size(min = 0,max=Integer.MAX_VALUE) int duration, float... values){
 LogUtils.e("addThen");
 if(view==null){
 throw new RuntimeException("view     ");
 }
 mIsPlaying = true;
 mView = view;
 ObjectAnimator thenAnimator = ObjectAnimator.ofFloat(view,animName,values);
 thenAnimator.setInterpolator(interpolator==null?mTimeInterpolator:interpolator);
 thenAnimator.setRepeatCount(repeatCount<0?0:repeatCount);
 thenAnimator.setDuration(duration<0?mDuration:duration);
 if (thenListener!=null&&thenListener.animatorListener != null) {
 thenAnimator.addListener(thenListener.animatorListener);
 }
 if(thenListener!=null&&thenListener.updateListener!=null){
 thenAnimator.addUpdateListener(thenListener.updateListener);
 }
 if(thenListener!=null&&thenListener.pauseListener!=null){
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  thenAnimator.addPauseListener(thenListener.pauseListener);
 }else{
  throw new RuntimeException("SDK    19");
 }
 }
 mAnimatorList.add(thenAnimator);
 return this;
 }
 public AnimatorSetWrap then(Animator animator) {
 mAnimatorList.add(animator);
 return this;
 }
 public AnimatorSetWrap then(AnimatorSetWrap animator) {
 mAnimatorList.add(animator.getAnimatorSet());
 return this;
 }
 /**
 * AnimatorSet Play  ,            
 *       play       mAnimatorList                
 * @param view     
 * @param animName     
 * @param interpolator    
 * @param repeatCount     
 * @param duration     
 * @param values      
 * @return
 */
 public AnimatorSetWrap play(View view, String animName, @Nullable TimeInterpolator interpolator, @Size(min = 0,max=Integer.MAX_VALUE) int repeatCount, @Size(min = 0,max=Integer.MAX_VALUE) int duration, float... values){
 LogUtils.e("play");
 if(mIsPlaying){
 throw new RuntimeException("AnimatorSetWrap.play()        ");
 }
 if(view==null){
 throw new RuntimeException("view     ");
 }
 mIsPlaying = true;
 mView = view;
 ObjectAnimator playAnimator = ObjectAnimator.ofFloat(view,animName,values);
 playAnimator.setInterpolator(interpolator==null?mTimeInterpolator:interpolator);
 playAnimator.setRepeatCount(repeatCount<0?0:repeatCount);
 playAnimator.setDuration(duration<0?mDuration:duration);
 if (playListener!=null&&playListener.animatorListener != null) {
 playAnimator.addListener(playListener.animatorListener);
 }
 if(playListener!=null&&playListener.updateListener!=null){
 playAnimator.addUpdateListener(playListener.updateListener);
 }
 if(playListener!=null&&playListener.pauseListener!=null){
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  playAnimator.addPauseListener(playListener.pauseListener);
 }else{
  throw new RuntimeException("SDK    19");
 }
 }
 mAnimatorList.clear();
 mAnimatorBuilder=mAnimatorSet.play(playAnimator);
 return this;
 }
 public AnimatorSetWrap play(Animator animator) {
 mAnimatorList.clear();
 mAnimatorBuilder = mAnimatorSet.play(animator);
 return this;
 }
 public AnimatorSetWrap play(AnimatorSetWrap animator) {
 mAnimatorList.clear();
 mAnimatorBuilder = mAnimatorSet.play(animator.getAnimatorSet());
 return this;
 }
 /**
 * AnimatorSet Before  
 * @param view        View
 * @param animName     
 * @param interpolator    
 * @param repeatCount     
 * @param duration       
 * @param values       
 * @return
 */
 public AnimatorSetWrap before(View view, String animName,@Nullable TimeInterpolator interpolator, @Size(min = 0,max=Integer.MAX_VALUE) int repeatCount,@Size(min = 0,max=Integer.MAX_VALUE)int duration, float... values){
 LogUtils.e("before");
 if(view==null){
 throw new RuntimeException("view     ");
 }
 ObjectAnimator beforeAnimator = ObjectAnimator.ofFloat(view,
  animName, values).setDuration(duration);
 beforeAnimator.setInterpolator(interpolator==null?mTimeInterpolator:interpolator);
 beforeAnimator.setRepeatCount(repeatCount<0?0:repeatCount);
 beforeAnimator.setDuration(duration<0?mDuration:duration);
 if (beforeListener!=null&&beforeListener.animatorListener != null) {
 beforeAnimator.addListener(beforeListener.animatorListener);
 }
 if(beforeListener!=null&&beforeListener.updateListener!=null){
 beforeAnimator.addUpdateListener(beforeListener.updateListener);
 }
 if(beforeListener!=null&&beforeListener.pauseListener!=null){
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  beforeAnimator.addPauseListener(beforeListener.pauseListener);
 }else{
  throw new RuntimeException("SDK    19");
 }
 }
 mAnimatorBuilder = mAnimatorBuilder.before(beforeAnimator);
 return this;
 }
 public AnimatorSetWrap before(Animator animator) {
 mAnimatorBuilder = mAnimatorBuilder.before(animator);
 return this;
 }
 public AnimatorSetWrap before(AnimatorSetWrap animator) {
 mAnimatorBuilder = mAnimatorBuilder.before(animator.getAnimatorSet());
 return this;
 }
 public AnimatorSetWrap with(View view, String animName,@Nullable TimeInterpolator interpolator,@Size(min = 0,max=Integer.MAX_VALUE) int repeatCount,@Size(min = 0,max=Integer.MAX_VALUE)int duration, float... values){
 LogUtils.e("with");
 if(view==null){
 throw new RuntimeException("view     ");
 }
 ObjectAnimator withAnimator = ObjectAnimator.ofFloat(view,
  animName, values).setDuration(duration);
 withAnimator.setInterpolator(interpolator==null?mTimeInterpolator:interpolator);
 withAnimator.setRepeatCount(repeatCount<0?0:repeatCount);
 withAnimator.setDuration(duration<0?mDuration:duration);
 if (withListener!=null&&withListener.animatorListener != null) {
 withAnimator.addListener(withListener.animatorListener);
 }
 if(withListener!=null&&withListener.updateListener!=null){
 withAnimator.addUpdateListener(withListener.updateListener);
 }
 if(withListener!=null&&withListener.pauseListener!=null){
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  withAnimator.addPauseListener(withListener.pauseListener);
 }else{
  throw new RuntimeException("SDK    19");
 }
 }
 mAnimatorBuilder = mAnimatorBuilder.with(withAnimator);
 return this;
 }
 public AnimatorSetWrap with(Animator animator) {
 mAnimatorBuilder = mAnimatorBuilder.with(animator);
 return this;
 }
 public AnimatorSetWrap with(AnimatorSetWrap animator) {
 mAnimatorBuilder = mAnimatorBuilder.with(animator.getAnimatorSet());
 return this;
 }
 public AnimatorSetWrap after(View view, String animName,@Nullable TimeInterpolator interpolator,@Size(min = 0,max=Integer.MAX_VALUE) int repeatCount,@Size(min = 0,max=Integer.MAX_VALUE) int duration, float... values){
 LogUtils.e("after");
 if(view==null){
 throw new RuntimeException("view     ");
 }
 ObjectAnimator afterAnimator = ObjectAnimator.ofFloat(view,
  animName, values).setDuration(duration);
 afterAnimator.setInterpolator(interpolator==null?mTimeInterpolator:interpolator);
 afterAnimator.setRepeatCount(repeatCount<0?0:repeatCount);
 afterAnimator.setDuration(duration<0?mDuration:duration);
 if (afterListener!=null&&afterListener.animatorListener != null) {
 afterAnimator.addListener(afterListener.animatorListener);
 }
 if(afterListener!=null&&afterListener.updateListener!=null){
 afterAnimator.addUpdateListener(afterListener.updateListener);
 }
 if(afterListener!=null&&afterListener.pauseListener!=null){
 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  afterAnimator.addPauseListener(afterListener.pauseListener);
 }else{
  throw new RuntimeException("SDK    19");
 }
 }
 mAnimatorBuilder = mAnimatorBuilder.after(afterAnimator);
 return this;
 }
 public AnimatorSetWrap after(Animator animator) {
 mAnimatorBuilder = mAnimatorBuilder.after(animator);
 return this;
 }
 public AnimatorSetWrap after(AnimatorSetWrap animator) {
 mAnimatorBuilder = mAnimatorBuilder.after(animator.getAnimatorSet());
 return this;
 }
 public AnimatorSetWrap after(long delay) {
 mAnimatorBuilder.after(delay);
 return this;
 }
 /**
 *       ,           AnimatorSet     
 *   mAnimatorList  0          
 */
 public void playAnim() {
 if(mAnimatorList.size()>0){
 readyThen(true);
 }
 mAnimatorSet.start();
 }
 /**
 *               
 *   mAnimatorList  0          
 * @param duration     
 */
 public void playAnim(long duration) {
 if(mAnimatorList.size()>0){
 readyThen(true);
 }
 mAnimatorSet.setDuration(duration);
 mAnimatorSet.start();
 }
 /**
 *           
 *   mAnimatorList  0          
 * @param delay     
 */
 public void playAnimDelay(long delay) {
 if(mAnimatorList.size()>0){
 readyThen(true);
 }
 mAnimatorSet.setStartDelay(delay);
 mAnimatorSet.start();
 }
 /**
 *       ,           AnimatorSet     
 */
 public void playAnim(boolean isSequentially) {
 readyThen(isSequentially);
 mAnimatorSet.start();
 }
 /**
 *               
 * @param duration     
 */
 public void playAnim(boolean isSequentially,long duration) {
 readyThen(isSequentially);
 mAnimatorSet.setDuration(duration);
 mAnimatorSet.start();
 }
 /**
 *           
 * @param delay     
 */
 public void playAnimDelay(boolean isSequentially,long delay) {
 readyThen(isSequentially);
 mAnimatorSet.setStartDelay(delay);
 mAnimatorSet.start();
 }
 /**
 *       
 * @param isSequentially            
 */
 private void readyThen(boolean isSequentially){
 //            
 if (mHasInitThenAnim) {
 return;
 }
 mHasInitThenAnim = true;
 if (mAnimatorList.size() > 0) {
 AnimatorSet set = new AnimatorSet();
 if(isSequentially){
  set.playSequentially(mAnimatorList);
 }else{
  set.playTogether(mAnimatorList);
 }
 mAnimatorBuilder.before(set);
 }
 }
 /**
 *     
 */
 public void cancel() {
 mAnimatorSet.cancel();
 mAnimatorList.clear();
 }
 /**
 *   AnimatorSet   
 * @return
 */
 private AnimatorSet getAnimatorSet() {
 return mAnimatorSet;
 }
 /**
 *  AnimatorSet    
 * @param listener
 * @return
 */
 public AnimatorSetWrap setAnimatorSetListener(Animator.AnimatorListener listener) {
 mAnimatorSet.addListener(listener);
 return this;
 }
 /**
 *   AnimatorSet   
 * @param listener
 */
 public void removeSetListner(Animator.AnimatorListener listener) {
 mAnimatorSet.removeListener(listener);
 }
 /**
 *     AnimatorSet   
 */
 public void removeAllLSetisteners() {
 mAnimatorSet.removeAllListeners();
 }
 /**
 *     View           (      )
 * @param mView
 * @return   true   
 */
 public static boolean isVisibleOnScreen(View mView) {
 if (mView == null) {
 return false;
 }
 return mView.getWindowVisibility() == View.VISIBLE
  && mView.getVisibility() == View.VISIBLE && mView.isShown();
 }
 }
 /**
 * Play     ObjectAnimator     
 */
 public static class PlayAnimationListener implements IAnimatorListener<PlayAnimationListener>{
 private Animator.AnimatorListener animatorListener;
 private ValueAnimator.AnimatorUpdateListener updateListener;
 private Animator.AnimatorPauseListener pauseListener;
 public AnimatorSetWrap animatorSetWrap;
 public PlayAnimationListener(AnimatorSetWrap animatorSetWrap){
 this.animatorSetWrap=animatorSetWrap;
 }
 @Override
 public PlayAnimationListener setAnimatorListener(Animator.AnimatorListener animatorListener) {
 this.animatorListener=animatorListener;
 return this;
 }
 @Override
 public PlayAnimationListener setUpdateListener(ValueAnimator.AnimatorUpdateListener animatorListener) {
 this.updateListener=animatorListener;
 return this;
 }
 @Override
 public PlayAnimationListener setPauseListener(Animator.AnimatorPauseListener animatorListener) {
 this.pauseListener=animatorListener;
 return this;
 }
 @Override
 public AnimatorSetWrap and(){
 return animatorSetWrap;
 }
 }
 public static class BeforeAnimationListener implements IAnimatorListener<BeforeAnimationListener>{
 private Animator.AnimatorListener animatorListener;
 private ValueAnimator.AnimatorUpdateListener updateListener;
 private Animator.AnimatorPauseListener pauseListener;
 public AnimatorSetWrap animatorSetWrap;
 public BeforeAnimationListener(AnimatorSetWrap animatorSetWrap){
 this.animatorSetWrap=animatorSetWrap;
 }
 @Override
 public AnimatorSetWrap and() {
 return animatorSetWrap;
 }
 @Override
 public BeforeAnimationListener setAnimatorListener(Animator.AnimatorListener listener) {
 this.animatorListener=listener;
 return this;
 }
 @Override
 public BeforeAnimationListener setUpdateListener(ValueAnimator.AnimatorUpdateListener listener) {
 this.updateListener=listener;
 return this;
 }
 @Override
 public BeforeAnimationListener setPauseListener(Animator.AnimatorPauseListener listener) {
 this.pauseListener=listener;
 return this;
 }
 }
 public static class WithAnimationListener implements IAnimatorListener<WithAnimationListener>{
 private Animator.AnimatorListener animatorListener;
 private ValueAnimator.AnimatorUpdateListener updateListener;
 private Animator.AnimatorPauseListener pauseListener;
 public AnimatorSetWrap animatorSetWrap;
 public WithAnimationListener(AnimatorSetWrap animatorSetWrap){
 this.animatorSetWrap=animatorSetWrap;
 }
 @Override
 public AnimatorSetWrap and() {
 return animatorSetWrap;
 }
 @Override
 public WithAnimationListener setAnimatorListener(Animator.AnimatorListener listener) {
 this.animatorListener=listener;
 return this;
 }
 @Override
 public WithAnimationListener setUpdateListener(ValueAnimator.AnimatorUpdateListener listener) {
 this.updateListener=listener;
 return this;
 }
 @Override
 public WithAnimationListener setPauseListener(Animator.AnimatorPauseListener listener) {
 this.pauseListener=listener;
 return this;
 }
 }
 public static class AfterAnimationListener implements IAnimatorListener<AfterAnimationListener>{
 private Animator.AnimatorListener animatorListener;
 private ValueAnimator.AnimatorUpdateListener updateListener;
 private Animator.AnimatorPauseListener pauseListener;
 public AnimatorSetWrap animatorSetWrap;
 public AfterAnimationListener(AnimatorSetWrap animatorSetWrap){
 this.animatorSetWrap=animatorSetWrap;
 }
 @Override
 public AnimatorSetWrap and() {
 return animatorSetWrap;
 }
 @Override
 public AfterAnimationListener setAnimatorListener(Animator.AnimatorListener listener) {
 this.animatorListener=listener;
 return this;
 }
 @Override
 public AfterAnimationListener setUpdateListener(ValueAnimator.AnimatorUpdateListener listener) {
 this.updateListener=listener;
 return this;
 }
 @Override
 public AfterAnimationListener setPauseListener(Animator.AnimatorPauseListener listener) {
 this.pauseListener=listener;
 return this;
 }
 }
 public static class ThenAnimationListener implements IAnimatorListener<ThenAnimationListener>{
 private Animator.AnimatorListener animatorListener;
 private ValueAnimator.AnimatorUpdateListener updateListener;
 private Animator.AnimatorPauseListener pauseListener;
 public AnimatorSetWrap animatorSetWrap;
 public ThenAnimationListener(AnimatorSetWrap animatorSetWrap){
 this.animatorSetWrap=animatorSetWrap;
 }
 @Override
 public AnimatorSetWrap and() {
 return animatorSetWrap;
 }
 @Override
 public ThenAnimationListener setAnimatorListener(Animator.AnimatorListener listener) {
 this.animatorListener=listener;
 return this;
 }
 @Override
 public ThenAnimationListener setUpdateListener(ValueAnimator.AnimatorUpdateListener listener) {
 this.updateListener=listener;
 return this;
 }
 @Override
 public ThenAnimationListener setPauseListener(Animator.AnimatorPauseListener listener) {
 this.pauseListener=listener;
 return this;
 }
 }
 /**
 *            
 * @param <T>
 */
 interface IAnimatorListener<T>{
 /**
 *   AnimatorListener   
 * @param listener
 * @return
 */
 T setAnimatorListener(Animator.AnimatorListener listener);
 /**
 *   AnimatorUpdateListener   
 * @param listener
 * @return
 */
 T setUpdateListener(ValueAnimator.AnimatorUpdateListener listener);
 /**
 *   AnimatorPauseListener   
 * @param listener
 * @return
 */
 T setPauseListener(Animator.AnimatorPauseListener listener);
 /**
 *                
 * @return
 */
 AnimatorSetWrap and();
 }
}사용 방법:
AnimatorUtils.createAnimator().play(viewAnimator,AnimatorUtils.ROTATIONY,null,0,1000,0,360).toAddThenListener().setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  @Override
  public void onAnimationUpdate(ValueAnimator valueAnimator) {
  LogUtils.e("then1:"+valueAnimator.getAnimatedValue());
  }
 }).and().then(viewAnimator, AnimatorUtils.TRANSY, null, -1, -2, 0, 100, 200, 300, 200, 100, 0).toAddThenListener().setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  @Override
  public void onAnimationUpdate(ValueAnimator valueAnimator) {
  LogUtils.e("then2:"+valueAnimator.getAnimatedValue());
  }
 }).and().then(viewAnimator, AnimatorUtils.SCALEX, new LinearInterpolator(), 0, 1000, 0, 10).toAddWithListener().setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  @Override
  public void onAnimationUpdate(ValueAnimator valueAnimator) {
  LogUtils.e("with1:"+valueAnimator.getAnimatedValue());
  }
 }).and().with(viewAnimator, AnimatorUtils.SCALEY, new LinearInterpolator(), 0, 1000, 0, 10).toAddWithListener().setAnimatorListener(new Animator.AnimatorListener() {
  @Override
  public void onAnimationStart(Animator animator) {
  LogUtils.e("with2:onAnimationStart");
  }
  @Override
  public void onAnimationEnd(Animator animator) {
  }
  @Override
  public void onAnimationCancel(Animator animator) {
  }
  @Override
  public void onAnimationRepeat(Animator animator) {
  }
 }).and().with(viewAnimator, AnimatorUtils.ALPHA, new LinearInterpolator(), 0, 1000, 1, 0,1)
 //.playSequentially(2000);
 .playAnim();위의 애니메이션 호출 방법 은 제 가 낙서 한 것 입 니 다.구체 적 으로 도구 류 의 사용 방법 을 보 여주 기 위해 서 입 니 다.당신 은 자신의 호출 방법 으로 바 꿀 수 있 습 니 다.총결산
이상 은 이 글 의 모든 내용 입 니 다.본 고의 내용 이 여러분 의 학습 이나 업무 에 어느 정도 참고 학습 가 치 를 가지 기 를 바 랍 니 다.여러분 의 저희 에 대한 지지 에 감 사 드 립 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.