activivty_main.xml

<?xml version="1.0" encoding="utf-8"?>                            

MainActivity.java

package com.example.yanhsama.ex4_12;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;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;import android.view.View.OnClickListener;public class MainActivity extends AppCompatActivity {    private Button rotateButton = null;    private Button scaleButton = null;    private Button alphaButton = null;    private Button translateButton = null;    private ImageView image = null;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        rotateButton = (Button)findViewById(R.id.rotateButton);        scaleButton = (Button)findViewById(R.id.scaleButton);        alphaButton = (Button)findViewById(R.id.alphaButton);        translateButton = (Button)findViewById(R.id.translateButton);        image = (ImageView)findViewById(R.id.image);        rotateButton.setOnClickListener(new RotateButtonListener());        scaleButton.setOnClickListener(new ScaleButtonListener());        alphaButton.setOnClickListener(new AlphaButtonListener());        translateButton.setOnClickListener(new TranslateButtonListener());    }    class RotateButtonListener implements OnClickListener{        public void onClick(View v) {            AnimationSet animationSet = new AnimationSet(true);            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);        }    }    class ScaleButtonListener implements OnClickListener{        public void onClick(View v) {            AnimationSet animationSet = new AnimationSet(true);            ScaleAnimation scaleAnimation = new ScaleAnimation(                    0,   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);        }    }    class AlphaButtonListener implements OnClickListener{        public void onClick(View v) {            //创建一个AnimationSet对象,参数为Boolean型,            AnimationSet animationSet = new AnimationSet(true);            //创建一个AlphaAnimation对象,参数从完全不透明度,到完全透明            AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);            //设置动画执行的时间            alphaAnimation.setDuration(500);            //将alphaAnimation对象添加到AnimationSet当中            animationSet.addAnimation(alphaAnimation);            //使用ImageView的startAnimation方法执行动画            image.startAnimation(animationSet);        }    }    class TranslateButtonListener implements OnClickListener{        public void onClick(View v) {            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);        }    }}

运行效果显示

android:编写一个补间动画(旋转,淡出淡入,缩放,移动)_第1张图片

更多相关文章

  1. 【Android】【绘图】绘制波浪线动画
  2. Android中颜色透明度对应16进制值
  3. AndroidのTween动画实现
  4. Android 补间动画(动画列表,平移,旋转,缩放,渐变,动画集合)
  5. android使用属性动画代替补间动画
  6. Android 播放Gif 动画
  7. Android最简单播放GIF动画方法
  8. Android 动画——Frame Animation与Tween Animation

随机推荐

  1. 手把手教你白嫖一个服务器并搭建自己的远
  2. Matplotlib 中等高线图(contour)的绘制
  3. 努力不一定能成,不努力一定不成
  4. 【Android】实现登录、注册、数据库操作(
  5. 万字长文详解Python正则表达式及re模块
  6. 浅谈生活中的短网址和短ID
  7. Markdown中输入数学公式及LaTex常用数学
  8. 笔试练习题(十)
  9. 偷学Python第二十九|time模块和calendar模
  10. “三本”如何高效自学前端四个月逆袭