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. linux 查看 cpu 和内存的命令 - top

    1.查看内存,cpu ,当前进程task数目, 每个进程的cpu, 内存使用率, 用top 命令: 在这个页面,按 P,下面的进程排序,以cpu使用率降序排列. 按M,按内存使用率降序排列: 按N, ...

  2. Java导出Excel表(poi)名中文乱码问题处理

    <pre name="code" class="java">String _filename = ValidateTools.date2Str(da ...

  3. 【HDU 5833】Zhu and 772002(异或方程组高斯消元讲解)

    题目大意:给出n个数字a[],将a[]分解为质因子(保证分解所得的质因子不大于2000),任选一个或多个质因子,使其乘积为完全平方数.求其方法数. 学长学姐们比赛时做的,当时我一脸懵逼的不会搞……所以 ...

  4. C语言根据函数名调用对应的函数

    通过函数指针定义,调用时加上参数 struct Command { const char *name; const char *desc; // return -1 to force monitor ...

  5. oracle中的常用函数1-------decode方法

    DECODE函数是ORACLE PL/SQL是功能强大的函数之一,目前还只有ORACLE公司的SQL提供了此函数,其他数据库厂商的SQL实现还没有此功能.DECODE有什么用途呢? 先构造一个例子,假 ...

  6. OVS - commands

    journalctl -t ovs-vswitchd ovs-vsctl show ovs-ofctl show br0 set vlanid ovs-vsctl set port eth0 tag= ...

  7. PARTITION BY 和 group by

    sum()   over   (PARTITION   BY   ...)   是一个分析函数.   他执行的效果跟普通的sum   ...group   by   ...不一样,它计算组中表达式的累 ...

  8. sessionStorage用于分页,瀑布流和存储用户数据等

    在手机网页开发中,会用到分页和瀑布流来分量显示数据.这里会遇到一个问题.当点击某条数据进入详情后,再按手机的返回键会到上一个页面,该页面是重新加载的. 本人在微信里用内置的qq浏览器打开页面,wind ...

  9. byte 读写文件

    import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import ja ...

  10. 【linux系统学习】计算机硬件核心知识

    (一)企业里PC服务器品牌及型号 互联网公司服务器品牌:DELL,HP,IBM(百度):国内品牌:浪潮,联想,航天联志 DELL服务器品牌:1u = 4.45CM 2010年前 1u 1850,195 ...