Android动画(Animations)
动画类型
Android的animation由四种类型组成
XML中
alpha : 渐变透明度动画效果
scale :渐变尺寸伸缩动画效果
translate : 画面转换位置移动动画效果
rotate :画面转移旋转动画效果
Java代码中
AlphaAnimation : 渐变透明度动画效果
ScaleAnimation :渐变尺寸伸缩动画效果
TranslateAnimation : 画面转换位置移动动画效果
RotateAnimation :画面转移旋转动画效果
1、main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/rotateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="旋转" />
<Button
android:id="@+id/scaleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="缩放" />
<Button
android:id="@+id/alphaButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="淡入淡出" />
<Button
android:id="@+id/translateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="移动" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/an" />
</LinearLayout>
</LinearLayout>
2、.java文件
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;
public class Animation1Activity extends Activity{
private Button rotateButton = null;
private Button scaleButton = null;
private Button alphaButton = null;
private Button translateButton = null;
private ImageView mImageView = null;
private Animation Alpha;
private Animation Scale;
private Animation Translate;
private AnimationRotate;
@Override
public void onCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.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);
mImageView = (ImageView)findViewById(R.id.image); rotateButton.setOnClickListener(newRotateButtonListener());
scaleButton.setOnClickListener(newScaleButtonListener());
alphaButton.setOnClickListener(newAlphaButtonListener());
translateButton.setOnClickListener(
new TranslateButtonListener());
}
class AlphaButtonListener implementsOnClickListener{
public void onClick(Viewv) {
Alpha= animationUtils.loadAnimation(this,R.anim.alpha_action);
mImageView.startAnimation(Alpha);
}
}
class RotateButtonListener implementsOnClickListener{
public void onClick(Viewv) { Rotate = AnimationUtils.loadAnimation(this,R.anim.rotate_action);
mImageView.startAnimation(Rotate);
}
class ScaleButtonListener implementsOnClickListener{
public void onClick(Viewv) {
Scale =AnimationUtils.loadAnimation(this,R.anim.scale_action);
mImageView.startAnimation(Scale);
}
class TranslateButtonListener implementsOnClickListener{
public void onClick(Viewv) {
Translate =AnimationUtils.loadAnimation(this,R.anim.translate_action);
mImageView.startAnimation(Translate);
}
}
}
1: alpha_action.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.1"
android:toAlpha="1.0"
android:duration="3000"
/>
</set>
2:rotate_action.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="0"
android:toDegrees="+350"
android:pivotX="50%"
android:pivotY="50%"
android:duration="3000"/>
</set>
3: scale_action.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="0.0"
android:toXScale="1.4"
android:fromYScale="0.0"
android:toYScale="1.4"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false"
android:duration="700"/>
</set> 4: translate_action.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="30"
android:toXDelta="-80"
android:fromYDelta="30"
android:toYDelta="300"
android:duration="2000"/>
</set>
下载地址
http://download.csdn.net/detail/dickyqie/9558580
Android动画(Animations)的更多相关文章
- 有趣的动画视图集合:Android View Animations
Android View Animations这个项目收集了各种有趣的动画效果. 所有效果: Attension Flash, Pulse, RubberBand, Shake, Swing, Wob ...
- Android动画效果之Frame Animation(逐帧动画)
前言: 上一篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画),今天来总结下Android的另外一种动画Frame ...
- Android 动画详解
这次主要就介绍android动画,android动画目前分为三种形式,Tween Animation 这个只能应用于view对象上面的,Drawable Animation这个是帧动画,就是类似我们有 ...
- 从源码角度理解android动画Interpolator类的使用
做过android动画的人对Interpolator应该不会陌生,这个类主要是用来控制android动画的执行速率,一般情况下,如果我们不设置,动画都不是匀速执行的,系统默认是先加速后减速这样一种动画 ...
- 《Android开发艺术探索》读书笔记 (7) 第7章 Android动画深入分析
本节和<Android群英传>中的第七章Android动画机制与使用技巧有关系,建议先阅读该章的总结 第7章 Android动画深入分析 7.1 View动画 (1)android动画分为 ...
- Android 动画animation 深入分析
转载请注明出处:http://blog.csdn.net/farmer_cc/article/details/18259117 Android 动画animation 深入分析 前言:本文试图通过分析 ...
- 深入分析Android动画(一)
动画的分类: ①View动画 View动画顾名思义其作用对象为View,包含平移.缩放.旋转.透明,这四类变化分别对应着Animation的子类TranlateAnimation.ScaleAnima ...
- Android动画深入分析
动画分类 Android动画可以分3种:View动画,帧动画和属性动画:属性动画为API11的新特性,在低版本是无法直接使用属性动画的,但可以用nineoldAndroids来实现(但是本质还是vii ...
- Android群英传笔记——第七章:Android动画机制和使用技巧
Android群英传笔记--第七章:Android动画机制和使用技巧 想来,最 近忙的不可开交,都把看书给冷落了,还有好几本没有看完呢,速度得加快了 今天看了第七章,Android动画效果一直是人家中 ...
- 公共技术点(Android 动画基础)
转载地址:http://p.codekk.com/blogs/detail/559623d8d6459ae793499787 一 传统 View 动画(Tween/Frame) 1.1 Tween 动 ...
随机推荐
- php CI 实战教程第一季百度经验杂志
phpCI实战教程第一季_百度经验杂志_百度经验http://jingyan.baidu.com/magazine/16428 杂志为本人php CI实战教程系列经验 从实际项目使用中写系列实战经验, ...
- IP分片丢失重传
尽管IP分片看起来是是透明的,但有一点让人不想使用它:即使只丢失一片数据也要重传整个数据报.为什么会发生这种情况呢? 因为IP层本身没有超时重传的机制——由更高层来负责超时和重传(TCP有超时 ...
- Django框架----基础
一个小问题: 什么是根目录:就是没有路径,只有域名..url(r'^$') 补充一张关于wsgiref模块的图片 一.MTV模型 Django的MTV分别代表: Model(模型):和数据库相关的,负 ...
- JavaScript Image对象 / Tabel对象 / Select对象 / Form对象
JavaScript Image / Tabel / Select / Form 对象 版权声明:未经授权,严禁转载! Image 对象 Image 对象,代表 <img> 元素. < ...
- 20145314郑凯杰《网络对抗技术》恶意DLL注入进程(进程捆绑)的实现
20145314郑凯杰<网络对抗技术>恶意DLL注入进程(进程捆绑)的实现 一.本节摘要 简介:在这部分里,要实现将恶意后门悄无声息地与进程进行捆绑,通过和已运行的进程进行捆绑,达到附着攻 ...
- [Java]接受拖拽文件的窗口
至于这个问题,Java的awt.dnd包下提供了许多完成这一功能的类 例如DropTarget.DropTargetListener等 先来讲一下DropTarget类,这个类完成和拖拽.复制文件等操 ...
- TCP客户端【TcpClient】
一.阻塞模式 1.命名空间 System.Net.Sockets 2.对象声明 TcpClient dpu1TcpClient = null;//dpu1tcp客户端,TcpClient模式 Netw ...
- v-if和v-show区别
v-if和v-show区别 v-if判断是否要加载,可以减轻服务器压力,按需加载. v-show 利用了css的display,可以提高客户端的流畅度. 看需求使用那个,如果页面上会经常用到,用v-s ...
- C# 如何调用启动窗体
Program.cs中代码如下: using System; using System.Collections.Generic; using System.Windows.Forms; namespa ...
- 【TCP/IP详解 卷一:协议】TCP的小结
前言:TCP学习的综述 在学习TCP/IP协议的大头:TCP协议 的过程中,遇到了很多机制和知识点,详解中更是用了足足8章的内容介绍它. TCP协议作为 应用层 和 网络层 中间的 传输层协议,既要为 ...