Android 动画

  • 旋转动画
 RotateAnimation rotateAnimation = new RotateAnimation(0,-360,
                Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);
        LinearInterpolator interpolator = new LinearInterpolator(); //匀速器
        rotateAnimation.setInterpolator(interpolator);
        rotateAnimation.setDuration(6000);
        rotateAnimation.setRepeatCount(Animation.INFINITE);
        rotateAnimation.setRepeatMode(Animation.RESTART);
        mBiggerCircle.setAnimation(rotateAnimation);
        rotateAnimation.start();
  • AnimationUtils.loadAnimation
    xml文件:


    

    

    

Activity中使用:

 Animation animation = AnimationUtils.loadAnimation(PayResultActivity.this, R.anim.expand);
 mStuInfoContainer.setAnimation(animation);  //需要动画的控件去展示效果
  • 属性动画集
    下面是一个属性动画的集合,实现了平移和透明度的改变。里面有一个递归,一个控件实现该动画完毕后在让另一个控件实现该动画。
 private void startAnimation(View view, int time, int delayTime, int startY, int endY) {
        ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
        ObjectAnimator translationY = ObjectAnimator.ofFloat(view, "translationY", startY, endY);
        //动画集合,位移和透明动画
        AnimatorSet set = new AnimatorSet();
        set.playTogether(translationY, alpha);
        set.setStartDelay(delayTime);
        set.setDuration(time);
        set.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (index < 1) {
                    //递归
                    startAnimation(mMsgInfoContainer, 1000, 0, -100, 0);
//                    startAnimation(mMsgInfoContainer, 2000, 0, 0, 0);
                    index++;
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });

        set.start();
    }

你可能感兴趣的:(Android 动画)