浅谈Android 动画,带你进入动画的世界

package com.example.testdemo;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;/** * 动画演示 * @author zengtao 2015年6月10日 下午4:02:13 * */public class MainActivity extends Activity {private ImageView image;private Button alpha, scale, rotate, translate, start;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);initView();initLinstener();}private void initLinstener() {alpha.setOnClickListener(onClickListener);scale.setOnClickListener(onClickListener);rotate.setOnClickListener(onClickListener);translate.setOnClickListener(onClickListener);start.setOnClickListener(onClickListener);}private void initView() {image = (ImageView) findViewById(R.id.image);alpha = (Button) findViewById(R.id.alpha);scale = (Button) findViewById(R.id.scale);rotate = (Button) findViewById(R.id.rotate);translate = (Button) findViewById(R.id.trans);start = (Button) findViewById(R.id.start);}private void alpha() {AnimationSet animationSet = new AnimationSet(true);AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);alphaAnimation.setDuration(1000);animationSet.addAnimation(alphaAnimation);image.startAnimation(animationSet);}private void scale() {AnimationSet animationSet = new AnimationSet(true);ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.1f, 0, 0.1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);scaleAnimation.setDuration(1000);animationSet.addAnimation(scaleAnimation);image.startAnimation(animationSet);}private void rotate() {AnimationSet animationSet = new AnimationSet(true);RotateAnimation rotateAnimation = new RotateAnimation(0, 360);animationSet.addAnimation(rotateAnimation);image.startAnimation(animationSet);}private void translate() {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, 0.5f);translateAnimation.setDuration(1000);animationSet.addAnimation(translateAnimation);image.startAnimation(animationSet);}private void start() {AnimationSet animationSet = new AnimationSet(true);AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.0f);alphaAnimation.setDuration(1000);animationSet.addAnimation(alphaAnimation);RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);rotateAnimation.setDuration(1000);animationSet.addAnimation(rotateAnimation);image.startAnimation(animationSet);}OnClickListener onClickListener = new OnClickListener() {@Overridepublic void onClick(View v) {if (v == alpha) {alpha();} else if (v == scale) {scale();} else if (v == rotate) {rotate();} else if (v == translate) {translate();} else if (v == start) {start();}}};}

,夫妇一条心,泥土变黄金。

浅谈Android 动画,带你进入动画的世界

相关文章:

你感兴趣的文章:

标签云: