码迷,mamicode.com
首页 > 其他好文 > 详细

20 Animation

时间:2014-05-06 01:16:46      阅读:320      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   class   code   java   

4中特效对应四个类。

bubuko.com,布布扣
package mars.animations01;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    private ImageView imageView = null;
    private Button rotateButton = null;
    private Button scaleButton = null;
    private Button alphaButton = null;
    private Button translateButton = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        imageView = (ImageView) findViewById(R.id.imageViewId);

        rotateButton = (Button) findViewById(R.id.rotateButtonId);
        rotateButton.setOnClickListener(new RotateButtonListener());

        scaleButton = (Button) findViewById(R.id.scaleButtonId);
        scaleButton.setOnClickListener(new ScaleButtonListener());

        alphaButton = (Button) findViewById(R.id.alphaButtonId);
        alphaButton.setOnClickListener(new AlphaButtonListener());

        translateButton = (Button) findViewById(R.id.translateButtonId);
        translateButton.setOnClickListener(new TranslateButtonListener());
    }

    private class RotateButtonListener implements OnClickListener {

        @Override
        public void onClick(View view) {
            AnimationSet animationSet = new AnimationSet(true);
            RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
                    Animation.RELATIVE_TO_PARENT, 1f,
                    Animation.RELATIVE_TO_PARENT, 0f);
            rotateAnimation.setDuration(5000);
            animationSet.addAnimation(rotateAnimation);
            imageView.startAnimation(animationSet);
        }
    }

    private class ScaleButtonListener implements OnClickListener {

        @Override
        public void onClick(View view) {
            AnimationSet animationSet = new AnimationSet(true);
            ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.1f, 1, 0.1f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            animationSet.addAnimation(scaleAnimation);
            animationSet.setStartOffset(1000);
            animationSet.setFillAfter(true);
            animationSet.setFillBefore(false);
            animationSet.setDuration(2000);
            imageView.startAnimation(animationSet);
        }

    }

    private class AlphaButtonListener implements OnClickListener {

        @Override
        public void onClick(View view) {
            //创建一个AnimationSet对象
            AnimationSet animationSet = new AnimationSet(true);
            //创建一个AlphaAnimation对象
            AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
            //设置动画执行的时间(单位:毫秒)
            alphaAnimation.setDuration(1000);
            //将AlphaAnimation对象添加到AnimationSet当中
            animationSet.addAnimation(alphaAnimation);
            //使用ImageView的startAnimation方法开始执行动画
            imageView.startAnimation(animationSet);
        }

    }

    private class TranslateButtonListener implements OnClickListener {

        @Override
        public void onClick(View view) {
            AnimationSet animationSet = new AnimationSet(true);
            TranslateAnimation translateAnimation = new TranslateAnimation(
                    Animation.RELATIVE_TO_SELF, 0f,
                    Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0f,
                    Animation.RELATIVE_TO_SELF, 1.0f);
            translateAnimation.setDuration(1000);
            animationSet.addAnimation(translateAnimation);
            imageView.startAnimation(animationSet);
        }
    }
}
bubuko.com,布布扣

 

20 Animation,布布扣,bubuko.com

20 Animation

标签:android   style   blog   class   code   java   

原文地址:http://www.cnblogs.com/cliffhuang/p/3704248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!