利用代碼定義動畫

              TextView tv = (TextView) findViewById(R.id.tv);

                /**
                 * Scale動畫
                 */
                ScaleAnimation scaleAnim = new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                scaleAnim.setDuration(700);

                /**
                 * alpha動畫
                 */
                AlphaAnimation alphaAnim = new AlphaAnimation(1.0f, 0.1f);
                alphaAnim.setDuration(3000);
                alphaAnim.setFillBefore(true);

                /**
                 * RotateAnimation
                 */
                RotateAnimation rotateAnim = new RotateAnimation(0, -650, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                rotateAnim.setDuration(3000);
                rotateAnim.setFillAfter(true);

                /**
                 * TranslateAnimation
                 */
                TranslateAnimation translateAnim = new TranslateAnimation(Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -80,
                        Animation.ABSOLUTE, 0, Animation.ABSOLUTE, -80);
                translateAnim.setDuration(2000);
                translateAnim.setFillBefore(true);


                /**
                 * AnimationSet
                 */
                Animation alpha_Anim = new AlphaAnimation(1.0f, 0.1f);
                Animation scale_Anim = new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                Animation rotate_Anim = new RotateAnimation(0, 720, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

                AnimationSet setAnim = new AnimationSet(true);
                setAnim.addAnimation(alpha_Anim);
                setAnim.addAnimation(scale_Anim);
                setAnim.addAnimation(rotate_Anim);

                setAnim.setDuration(3000);
                setAnim.setFillAfter(true);


                tv.startAnimation(setAnim);

動畫監聽:ide

    private void AnimationListener(final TextView tv) {
        RotateAnimation rotateAnim = new RotateAnimation(0, -650, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnim.setDuration(3000);
        rotateAnim.setFillAfter(true);


        ScaleAnimation scaleAnim = new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        scaleAnim.setDuration(700);
        scaleAnim.setAnimationListener(new Animation.AnimationListener() {
            public void onAnimationStart(Animation animation) {
          //動畫開始回調
            }

            public void onAnimationEnd(Animation animation) {
                tv.startAnimation(rotateAnim);
         //動畫結束回調
            }

            public void onAnimationRepeat(Animation animation) {
         //動畫重複回調
            }
        });

        tv.startAnimation(scaleAnim);

    }
相關文章
相關標籤/搜索