ANDROID_MARS学习笔记_S02_007_Animation第一种使用方式:代码

一、简介

二、代码
1.xml
(1)activity_main.xml

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:orientation="vertical" android:layout_width="fill_parent"
 4     android:layout_height="fill_parent">
 5
 6     <Button android:id="@+id/scaleButtonId" android:layout_width="fill_parent"
 7         android:layout_height="wrap_content" android:layout_alignParentBottom="true"
 8         android:text="测试scale动画效果" />
 9
10     <Button android:id="@+id/rotateButtonId" android:layout_width="fill_parent"
11         android:layout_height="wrap_content" android:layout_above="@id/scaleButtonId"
12         android:text="测试rotate动画效果" />
13
14     <Button android:id="@+id/alphaButtonId" android:layout_width="fill_parent"
15         android:layout_height="wrap_content" android:layout_above="@id/rotateButtonId"
16         android:text="测试alpha动画效果" />
17
18     <Button android:id="@+id/translateButtonId"
19         android:layout_width="fill_parent" android:layout_height="wrap_content"
20         android:layout_above="@id/alphaButtonId" android:text="测试translate动画效果" />
21
22     <LinearLayout android:orientation="vertical"
23         android:layout_width="fill_parent" android:layout_height="fill_parent">
24
25         <ImageView android:id="@+id/imageViewId"
26             android:layout_width="wrap_content" android:layout_height="100dp"
27             android:layout_centerInParent="true" android:layout_marginTop="100dip"
28             android:src="@drawable/android" />
29     </LinearLayout>
30 </RelativeLayout>

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     @Override
21     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         @Override
41         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         @Override
54         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         @Override
69         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         @Override
80         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 }
时间: 2024-08-05 15:23:21

ANDROID_MARS学习笔记_S02_007_Animation第一种使用方式:代码的相关文章

ANDROID_MARS学习笔记_S02_008_ANIMATION第二种使用方式:xml

一.简介 二.代码1.res\anim下的xml(1)alpha.xml.xml 1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android" 3 android:interpolator="@android:anim/accelerate_interpolator&q

JavaScript新手学习笔记3——三种排序方式(冒泡排序、插入排序、快速排序)

每种编程语言学到数组的时候,都会讲到排序算法,当时学C语言的时候,卡在排序算法.今天来总结一下javascript中如何实现三种排序算法. 1.冒泡排序(默认升序排列哦) 原理: 冒泡排序的原理,顾名思义,就是小数往上冒,大数往下沉.从第一个数开始,如果比第二个数大就交换位置,然后跟第三个数字进行比较大小,交换位置等. 举例一下,有数组[2,4,3,5,1] 第一次循环:2<4  不交换:4>3 交换:4<5不交换:5>1交换,故结果是[2,3,4,1,5]; 第二次循环:2<

.NET Remoting学习笔记(二)激活方式

目录 .NET Remoting学习笔记(一)概念 .NET Remoting学习笔记(二)激活方式 参考:百度百科  ♂风车车.Net 激活方式概念 在访问远程类型的一个对象实例之前,必须通过一个名为Activation的进程创建它并进行初始化.这种客户端通过通道来创建远程对象,称为对象的激活. 激活分为两大类:服务器端激活  客户端激活 服务器端激活 又称WellKnow(知名对象) 服务器应用程序在激活对象实例之前会在一个众所周知的统一资源标识符(URI)上来发布这个类型.然后该服务器进程

APUE学习笔记:第一章 UNUX基础知识

1.2 UNIX体系结构 从严格意义上,可将操作系统定义为一种软件(内核),它控制计算机硬件资源,提供程序运行环境.内核的接口被称为系统调用.公用函数库构建在系统调用接口之上,应用软件即可使用公用函数库,也可使用系统调用.shell是一种特殊的应用程序,它为运行其他应用程序提供了一个接口 从广义上,操作系统包括了内核和一些其他软件,这些软件使得计算机能够发挥作用,并给予计算机以独有的特性(软件包括系统实用程序,应用软件,shell以及公用函数库等) 1.3  shell shell是一个命令行解

学习笔记:第一章——计算机网络概述

学习笔记:第一章--计算机网络概述 1.0 计算机网络的定义:一些互相连接的,自治的计算机的集合称为计算机网路. 1.1 计算机网络在信息时代中的作用:连通和共享. 1.2 因特网概述:       网络的概念:网络(network)是由若干个结点(node)和连接这些结点的链路(link)组成. 网络中的结点可以是计算机,集线器,交换机和路由器: 网络和网络是通过路由器连接: 因特网是世界上最大的网络. 1.3 因特网的组成: 从因特网的工作方式上将其分为以下两大快: (1)边缘部分:由所有的

Cocos2dx 学习笔记整理----第一个项目

接上一节, 进入新建的项目下面的proj.win32下面,找到项目名.sln文件(我的是game001.sln),双击会通过VS2010打开.(当然,你装了VS什么版本就是什么版本) 将你的项目设为启动项目, 切换到解决方案视图, 然后邮件点击解决方案, 选择生成解决方案. 第一次生成根据个人机器性能会消耗大概1-3分钟,呵呵. 但是以后会快很多的. 生成成功的话会在输出窗口显示如下: 一般都会生成成功,但是我生成的时候失败了很多次,后来发现是这个问题:http://www.cnblogs.co

Stealth视频教程学习笔记(第一章)

Stealth视频教程学习笔记(第一章) 本文是对Unity官方视频教程Stealth的学习笔记.在此之前,本人整理了Stealth视频的英文字幕,并放到了优酷上.本文将分别对各个视频进行学习总结,提炼出其中的知识点和思路思想. 视频地址在(http://www.youku.com/playlist_show/id_23389553.html),是一个Stealth的专辑,这里只放上第一个视频,其它的大家在上面的链接中慢慢看吧. 第二章有一个视频是FLV格式的,我没法把字幕嵌入其中,所以优酷上就

Citrix XenMobile学习笔记之七:XenMobile部署方式

XenMobile有3个版本,分别有不同的部署方式,既可以单独部署,也可以混合部署. XenMobile MDM版部署方式 部署方式一:在传统的DMZ区部署 部署方式二:在DMZ区后面部署(直通DMZ区) 部署方式三:负载均衡的MDM服务器部署 部署方式四:XNC的MDM部署 XenMobile App版部署方式 部署方式一:POC方式部署 部署方式二:和ShareFile集成部署 部署方式三:MDM和MAM集成部署 部署方式四:高可用部署 XenMobile Enterprise版部署方式 部

《七周七语言》学习笔记——Ruby——第一天:找个保姆

感觉学了东西很快就会忘记,不会留下什么,趁这次看<七周七语言>,把其中觉得有用的东西记录下来,方便以后自己查阅,这篇应该就是记录的开始了. Ruby是一门面向对象的.解释型的.动态类型的脚本语言.面向对象,说明了这门语言具有封装.继承.多态这些特性:解释型,意味着它由解释器而不是编译器来执行:动态类型,即类型是在运行时绑定而非编译时绑定:脚本语言,则说明了它很短!易上手!并且只在调用的时候解释执行. 编程模型:一切皆对象,从一个数到bool值,都被定义为对象,都有自己的方法 判断结构:块形式和