Animation:  1,AlphaAnimation, 透明度动画,

2, RotateAnimation, 旋转动画,

3,ScaleAnimation, 缩放动画

4,TranslateAnimation 位移动画

通过setDuration()设置动画时长,setAnimation()将想要的动画添加到你所想要的图片ImageView上。

note:如果想让一张图片具有多个动画的话,使用AnimationSet动画集合类,用addAnimation()添加想要的动画。

简单的Animation demo截图:

以下是XML布局和Java代码:

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:paddingBottom="@dimen/activity_vertical_margin"
     android:paddingLeft="@dimen/activity_horizontal_margin"
     android:paddingRight="@dimen/activity_horizontal_margin"
     android:paddingTop="@dimen/activity_vertical_margin"
     tools:context="com.example.android_animation.MainActivity" >

     <ImageView
         android:id="@+id/imageView1"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_alignParentTop="true"
         android:layout_centerHorizontal="true"
         android:layout_marginTop="28dp"
         android:src="@drawable/heihei" />

     <Button
         android:id="@+id/button1"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_alignLeft="@+id/button2"
         android:layout_below="@+id/imageView1"
         android:layout_marginTop="36dp"
         android:text="透明度动画" />

     <Button
         android:id="@+id/button2"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_alignLeft="@+id/button3"
         android:layout_below="@+id/button1"
         android:layout_marginTop="14dp"
         android:text="旋转动画" />

     <Button
         android:id="@+id/button3"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_alignLeft="@+id/button4"
         android:layout_below="@+id/button2"
         android:text="位移动画" />

     <Button
         android:id="@+id/button4"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_alignLeft="@+id/button5"
         android:layout_below="@+id/button3"
         android:text="缩放动画" />

     <Button
         android:id="@+id/button5"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_below="@+id/button4"
         android:layout_centerHorizontal="true"
         android:text="多种动画" />

 </RelativeLayout>

Animation XML布局

 package com.example.android_animation;

 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 MainActivity extends Activity implements OnClickListener {
     private ImageView imageview;
     private Button button1;
     private Button button2;
     private Button button3;
     private Button button4;
     private Button button5;
     private Animation animation;
     private Animation alphaanimation;
     private Animation translateanimation;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         imageview = (ImageView) findViewById(R.id.imageView1);
         // imageview.setImageResource(R.drawable.mao);
         button1 = (Button) findViewById(R.id.button1);
         button2 = (Button) findViewById(R.id.button2);
         button3 = (Button) findViewById(R.id.button3);
         button4 = (Button) findViewById(R.id.button4);
         button5 = (Button) findViewById(R.id.button5);
         button1.setOnClickListener(this);
         button2.setOnClickListener(this);
         button3.setOnClickListener(this);
         button4.setOnClickListener(this);
         button5.setOnClickListener(this);
     }

     @Override
     public void onClick(View v) {
         // TODO Auto-generated method stub
         switch (v.getId()) {
         case R.id.button1:
             // 透明度动画动画
             animation = new AlphaAnimation(0.1f, 1.0f);
             animation.setDuration(3000);
             imageview.setAnimation(animation);
             break;
         case R.id.button2:
             // 旋转动画
             animation = new RotateAnimation(0, 360);
             animation.setDuration(3000);
             imageview.setAnimation(animation);
             break;
         case R.id.button3:
             // 位移动画
             animation = new TranslateAnimation(0.1f, 1.0f, 1.0f, 100f);
             animation.setDuration(3000);
             imageview.setAnimation(animation);
             break;
         case R.id.button4:
             // 缩放动画
             animation = new ScaleAnimation(0.1f, 1.0f, 0.1f, 1.0f);
             animation.setDuration(3000);
             imageview.setAnimation(animation);
             break;
         case R.id.button5:
             // 多种动画
             alphaanimation = new AlphaAnimation(0.1f, 1.0f);
             translateanimation = new TranslateAnimation(0.1f, 1.0f, 1.0f, 100f);
             animation = new ScaleAnimation(0.1f, 1.0f, 0.1f, 1.0f);
             // 定义一个动画集合
             AnimationSet set = new AnimationSet(true);
             set.addAnimation(alphaanimation);
             set.addAnimation(animation);
             set.addAnimation(translateanimation);
             break;
         default:
             break;
         }
     }
 }

Animation Java代码

Animation动画的更多相关文章

  1. CSS3 animation 动画

    今天看到一个很酷的logo看了下他用的是animation 动画效果,就拿来做例子 浏览器支持 Internet Explorer 10.Firefox 以及 Opera 支持 animation 属 ...

  2. css3 animation动画特效插件的巧用

    这一个是css3  animation动画特效在线演示的网站 https://daneden.github.io/animate.css/ 下载 animate.css文件,文件的代码很多,不过要明白 ...

  3. Android Property Animation动画

    3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中又引入了一个新的动画系统:property animation,这三 ...

  4. android Animation 动画绘制逻辑

    参考:http://www.jianshu.com/p/3683a69c38ea 1.View.draw(Canvas) 其中步骤为:/* * Draw traversal performs seve ...

  5. 转 iOS Core Animation 动画 入门学习(一)基础

    iOS Core Animation 动画 入门学习(一)基础 reference:https://developer.apple.com/library/ios/documentation/Coco ...

  6. css3 animation动画技巧

    一,css3 animation动画前言 随着现在浏览器对css3的兼容性越来越好,使用css3动画来制作动画的例子也越来越广泛,也随着而来带来了许多的问题值得我们能思考.css3动画如何让物体运动更 ...

  7. 【Android 基础】Animation 动画介绍和实现

    在前面PopupWindow 实现显示仿腾讯新闻底部弹出菜单有用到Animation动画效果来实现菜单的显示和隐藏,本文就来介绍下吧. 1.Animation 动画类型 Android的animati ...

  8. css3 transition属性变化与animation动画的相似性以及不同点

    下面列子中的2个图片的效果. http://zqtest.e-horse.cn/DongXueImportedCar/assets/mouseOverAnimate.html 第一个为transiti ...

  9. Android中xml设置Animation动画效果详解

    在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...

  10. android中设置Animation 动画效果

    在 Android 中, Animation 动画效果的实现可以通过两种方式进行实现,一种是 tweened animation 渐变动画,另一种是 frame by frame animation ...

随机推荐

  1. C++函数后面的throw()

    看CImage函数实现的时候发现了这么个东东  inline HBITMAP CImage::Detach() throw() 它是函数提供者和使用者的一种君子协定,标明该函数不抛出任何异常. 之所以 ...

  2. 关于Spring的69个面试问答——终极列表

    本文由 ImportNew - 人晓 翻译自 javacodegeeks.欢迎加入翻译小组.转载请见文末要求. 这篇文章总结了一些关于Spring框架的重要问题,这些问题都是你在面试或笔试过程中可能会 ...

  3. iOS 2.0 版本切入点

    转载自:http://www.infoq.com/cn/articles/Version_2_0 移动互联网如火如荼,iOS 应用+ Android 应用+ 手机站似乎成了所有互联网公司的标配,你的网 ...

  4. IE6下整站的bug详解

    <1>文字不居中:加一个行高: <2>png文件作为背景不显示: <!--[if IE 6]> <script src="js/DD_belated ...

  5. hdu1426 Sudoku Killer

    Sudoku Killer Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total ...

  6. 【Qt开发】修改源码文件的编码格式的小技巧 .

    默认情况下,代码文件应该以utf-8的格式来存储的.而如果在代码文件的转移或者上传下载过程中,弄乱了文件的编码格式,一般会出现乱码的情况. 例如windows系统下,中文就很容易出现乱码,如下图,文件 ...

  7. CSS3简介

    选择器 盒模型 背景和边框 文字特效 2d/3d转换 动画 多列布局 用户界面

  8. 我终于有案例库啦(github 提供的)

    穷逼一个,一直在纠结要不要买个服务器什么的. 后来在慕课网看 git 教程时看到 github 可以帮你展示网页哟,于是我便有了这个案例库. 网址:https://foreverz133.github ...

  9. springMVC简单的安全防御配置

    1,使用 spring form 标签 防 csrf 攻击 2,标明请求方法:RequestMethod.GET,RequestMethod.POST, PATCH, POST, PUT, and D ...

  10. JSP内置对象--application对象(getRealPath(),getAttributeNames(),getContextPath())

    application对象是javax.servlet.ServletContext接口的实例化对象.是整个servlet的上下文,代表了整个web容器的操作. 常用方法: 1.java.lang.S ...