package com.example.thinkpad.animation;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.RotateAnimation;import android.view.animation.ScaleAnimation;import android.view.animation.TranslateAnimation;import android.widget.Button;import android.widget.ImageView;import android.widget.Toast;public class Main2Activity extends AppCompatActivity implements View.OnClickListener {    ImageView imageView;    TranslateAnimation translateAnimation;    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main2);        Toast.makeText(this,"hello",Toast.LENGTH_SHORT).show();        imageView=(ImageView) findViewById(R.id.image);        Button button0 =(Button) findViewById(R.id.bt_translation);        Button button1=(Button) findViewById(R.id.bt_rotate);        Button button2 =(Button) findViewById(R.id.bt_scale);        Button button3 =(Button) findViewById(R.id.bt_alpha);        button1.setOnClickListener(this);        button0.setOnClickListener(this);        button2.setOnClickListener(this);        button3.setOnClickListener(this);    }    public  void onClick(View v){        switch (v.getId()){            case R.id.bt_translation://平移                translateAnimation =new TranslateAnimation(Animation.RELATIVE_TO_PARENT,0,                        Animation.RELATIVE_TO_PARENT,1.0f,Animation.RELATIVE_TO_PARENT,0,Animation.RELATIVE_TO_PARENT,                        1.0f);                translateAnimation.setDuration(3000);                translateAnimation.setRepeatCount(Animation.INFINITE);                translateAnimation.setFillAfter(true);                translateAnimation.setRepeatMode(Animation.REVERSE);                imageView.startAnimation(translateAnimation);            break;            case R.id.bt_rotate://旋转                RotateAnimation rotateAnimation=new RotateAnimation(0,360,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f);                rotateAnimation.setRepeatCount(Animation.INFINITE);                rotateAnimation.setDuration(3000);                imageView.startAnimation(rotateAnimation);                break;            case R.id.bt_scale://缩放                ScaleAnimation scaleAnimation=new ScaleAnimation(Animation.RELATIVE_TO_SELF,0,1.5f,Animation.RELATIVE_TO_SELF,0,1.5f);                scaleAnimation.setDuration(3000);                scaleAnimation.setRepeatCount(3);                imageView.startAnimation(scaleAnimation);                break;            case R.id.bt_alpha://透明度                AlphaAnimation alphaAnimation=new AlphaAnimation(0,1);                alphaAnimation.setDuration(3000);                imageView.startAnimation(alphaAnimation);        }    }}

注意:需使用view类的startAnimation()开启动画而不是Animation类的start()或者startNow(),否则有可能不会及时播放动画。

更多相关文章

  1. Android(安卓)图片缩放与旋转
  2. Android(安卓)ViewPager动画第三方库(MagicViewPager)
  3. Android中位图缩放
  4. Android(安卓)动画框架代码分析
  5. Android(安卓)Animation动画(Frame-By-Frame Animations 、Tween
  6. Android(安卓)图片缩放
  7. 【Android】【Lottie】在Android中使用Lottie动画
  8. Android图形报表之AchartEngine(附开发包+API文档)
  9. android图片闪烁或帧动画

随机推荐

  1. Handler
  2. Android animation 学习
  3. android 数据传递详解(Serialization、Par
  4. Android(安卓)Sqlite数据库版本升级管理
  5. android各sdk,cpu_img,source,doc下载
  6. Android入门教程(二)之------环境搭建
  7. Android SDK 2.2 离线安装
  8. 三层缓存机制-新知识点,Android常见的内存
  9. android开发(二):android结构
  10. Android基础知识学习-Instrumentation启