博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ANDROID_MARS学习笔记_S02_007_Animation第一种使用方式:代码
阅读量:5282 次
发布时间:2019-06-14

本文共 4269 字,大约阅读时间需要 14 分钟。

一、简介

 

 

二、代码

1.xml
(1)activity_main.xml

1 
2
5 6
9 10
13 14
17 18
21 22
24 25
29
30

 

2.java

(1)MainActivity.java

1 package com.animation1; 2  3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.view.View; 6 import android.view.View.OnClickListener; 7 import android.view.animation.AlphaAnimation; 8 import android.view.animation.Animation; 9 import android.view.animation.AnimationSet;10 import android.view.animation.RotateAnimation;11 import android.view.animation.ScaleAnimation;12 import android.view.animation.TranslateAnimation;13 import android.widget.Button;14 import android.widget.ImageView;15 16 public class MainActivity extends Activity {17 18     private ImageView imageView = null;19     private Button rotateButton, scaleButton, alphaButton, translateButton = null;20     @Override21     protected void onCreate(Bundle savedInstanceState) {22         super.onCreate(savedInstanceState);23         setContentView(R.layout.activity_main);24         25         imageView = (ImageView) findViewById(R.id.imageViewId);26         27         rotateButton = (Button) findViewById(R.id.rotateButtonId);28         scaleButton = (Button) findViewById(R.id.scaleButtonId);29         alphaButton = (Button) findViewById(R.id.alphaButtonId);30         translateButton = (Button) findViewById(R.id.translateButtonId);31         32         rotateButton.setOnClickListener(new RotateButtonListener());33         scaleButton.setOnClickListener(new ScaleButtonListener());34         alphaButton.setOnClickListener(new AlphaButtonListener());35         translateButton.setOnClickListener(new TranslateButtonListener());36         37     }38     39     private class RotateButtonListener implements OnClickListener {40         @Override41         public void onClick(View v) {42             AnimationSet animationSet = new AnimationSet(true);43             RotateAnimation rotateAnimation = new RotateAnimation(0, 360, 44                     AnimationSet.RELATIVE_TO_PARENT, 1f,45                     Animation.RELATIVE_TO_PARENT, 0f);46             rotateAnimation.setDuration(5000);47             animationSet.addAnimation(rotateAnimation);48             imageView.startAnimation(animationSet);49         }50     }51     52     private class ScaleButtonListener implements OnClickListener {53         @Override54         public void onClick(View v) {55             AnimationSet animationSet = new AnimationSet(true);56             ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.1f, 1, 0.1f, 57                     Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);58             animationSet.addAnimation(scaleAnimation);59             animationSet.setStartOffset(1000);60             animationSet.setFillAfter(true);61             animationSet.setFillBefore(false);62             animationSet.setDuration(2000);63             imageView.startAnimation(animationSet);64         }65     }66     67     private class AlphaButtonListener implements OnClickListener {68         @Override69         public void onClick(View v) {70             AnimationSet animationSet = new AnimationSet(true);71             AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);72             alphaAnimation.setDuration(1000);73             animationSet.addAnimation(alphaAnimation);74             imageView.startAnimation(animationSet);75         }76     }77     78     private class TranslateButtonListener implements OnClickListener {79         @Override80         public void onClick(View v) {81             AnimationSet animationSet = new AnimationSet(true);82             TranslateAnimation translateAnimation = new TranslateAnimation(83                     Animation.RELATIVE_TO_SELF, 0f, 84                     Animation.RELATIVE_TO_SELF, 0.5f, 85                     Animation.RELATIVE_TO_SELF, 0f, 86                     Animation.RELATIVE_TO_SELF, 1.0f);87             translateAnimation.setDuration(1000);88             animationSet.addAnimation(translateAnimation);89             imageView.startAnimation(translateAnimation);90         }91     }92 }

 

 

 

转载于:https://www.cnblogs.com/shamgod/p/5201196.html

你可能感兴趣的文章
Hadoop基本概念
查看>>
java.util.zip压缩打包文件总结一:压缩文件及文件下面的文件夹
查看>>
浅说 apache setenvif_module模块
查看>>
MySQL--数据插入
查看>>
重新学习python系列(二)? WTF?
查看>>
shell脚本统计文件中单词的个数
查看>>
SPCE061A学习笔记
查看>>
sql 函数
查看>>
hdu 2807 The Shortest Path 矩阵
查看>>
熟悉项目需求,要知道产品增删修改了哪些内容,才会更快更准确的在该项目入手。...
查看>>
JavaScript 变量
查看>>
java实用类
查看>>
smarty模板自定义变量
查看>>
研究称90%的癌症由非健康生活习惯导致
查看>>
命令行启动Win7系统操作部分功能
查看>>
排序sort (一)
查看>>
Parrot虚拟机
查看>>
Teamcenter10 step-by-step installation in Linux env-Oracle Server Patch
查看>>
Struts2学习(三)
查看>>
Callable和Runnable和FutureTask
查看>>