一、简介

  

二、代码
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">
  4. <alpha
  5. android:fromAlpha="1.0"
  6. android:toAlpha="0.0"
  7. android:startOffset="500"
  8. android:duration="1000"/>
  9. </set>

(2)rotate.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">
  4. <rotate
  5. android:fromDegrees="0"
  6. android:toDegrees="720"
  7. android:pivotX="50%"
  8. android:pivotY="100%"
  9. android:duration="3000"/>
  10. </set>

(3)scale.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">
  4. <scale
  5. android:fromXScale="1.0"
  6. android:toXScale="0.0"
  7. android:fromYScale="1.0"
  8. android:toYScale="0.0"
  9. android:pivotX="50%"
  10. android:pivotY="50%"
  11. android:duration="2000"/>
  12.  
  13. </set>

(4)tranlate.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">
  4. <translate
  5. android:fromXDelta="50%"
  6. android:toXDelta="100%"
  7. android:fromYDelta="0%"
  8. android:toYDelta="100%"
  9. android:duration="2000"/>
  10. </set>

2.java
(1)MainActivity.java

  1. package com.animation2;
  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.Animation;
  8. import android.view.animation.AnimationUtils;
  9. import android.widget.Button;
  10. import android.widget.ImageView;
  11.  
  12. public class MainActivity extends Activity {
  13.  
  14. private ImageView imageView = null;
  15. private Button rotateButton = null;
  16. private Button scaleButton = null;
  17. private Button alphaButton = null;
  18. private Button translateButton = null;
  19.  
  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. rotateButton.setOnClickListener(new RotateButtonListener());
  29.  
  30. scaleButton = (Button) findViewById(R.id.scaleButtonId);
  31. scaleButton.setOnClickListener(new ScaleButtonListener());
  32.  
  33. alphaButton = (Button) findViewById(R.id.alphaButtonId);
  34. alphaButton.setOnClickListener(new AlphaButtonListener());
  35.  
  36. translateButton = (Button) findViewById(R.id.translateButtonId);
  37. translateButton.setOnClickListener(new TranslateButtonListener());
  38. }
  39.  
  40. class TranslateButtonListener implements OnClickListener {
  41. @Override
  42. public void onClick(View v) {
  43. Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.tranlate);
  44. imageView.startAnimation(animation);
  45. }
  46. }
  47.  
  48. class AlphaButtonListener implements OnClickListener {
  49. @Override
  50. public void onClick(View v) {
  51. Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.alpha);
  52. imageView.startAnimation(animation);
  53. }
  54. }
  55.  
  56. class ScaleButtonListener implements OnClickListener {
  57. @Override
  58. public void onClick(View v) {
  59. Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.scale);
  60. imageView.startAnimation(animation);
  61. }
  62. }
  63.  
  64. class RotateButtonListener implements OnClickListener {
  65. @Override
  66. public void onClick(View v) {
  67. Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.rotate);
  68. imageView.startAnimation(animation);
  69. }
  70. }
  71. }

ANDROID_MARS学习笔记_S02_008_ANIMATION第二种使用方式:xml的更多相关文章

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

    一.简介 二.代码1.xml(1)activity_main.xml <?xml version="1.0" encoding="utf-8"?> ...

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

    每种编程语言学到数组的时候,都会讲到排序算法,当时学C语言的时候,卡在排序算法.今天来总结一下javascript中如何实现三种排序算法. 1.冒泡排序(默认升序排列哦) 原理: 冒泡排序的原理,顾名 ...

  3. Stealth视频教程学习笔记(第二章)

    Stealth视频教程学习笔记(第二章) 本文是对Unity官方视频教程Stealth的学习笔记.在此之前,本人整理了Stealth视频的英文字幕,并放到了优酷上.本文将分别对各个视频进行学习总结,提 ...

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

    目录 .NET Remoting学习笔记(一)概念 .NET Remoting学习笔记(二)激活方式 .NET Remoting学习笔记(三)信道 参考:百度百科  ♂风车车.Net 激活方式概念 在 ...

  5. 【转载】.NET Remoting学习笔记(二)激活方式

    目录 .NET Remoting学习笔记(一)概念 .NET Remoting学习笔记(二)激活方式 .NET Remoting学习笔记(三)信道 参考:百度百科 ♂风车车.Net 激活方式概念 在访 ...

  6. 红帽学习笔记[RHCSA] 第二周

    目录 红帽学习笔记[RHCSA]第二周 环境 第七课[网络配置相关] 在Vmware中添加网卡 将网卡添加到虚拟机上 关于网卡命名规则 配置网络 网络配置命令总结 更改hostname 关于SSH的一 ...

  7. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十章:阴影贴图

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十章:阴影贴图 本章介绍一种在游戏和应用中,模拟动态阴影的基本阴影 ...

  8. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十二章:四元数(QUATERNIONS)

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十二章:四元数(QUATERNIONS) 学习目标 回顾复数,以及 ...

  9. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十一章:环境光遮蔽(AMBIENT OCCLUSION)

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第二十一章:环境光遮蔽(AMBIENT OCCLUSION) 学习目标 ...

随机推荐

  1. 使用MVCJqGrid的心得

    最近公司网站进行升级,项目要用.net mvc,mysql和轻量级orm框架dapper.由于美工页面出不来啊,让我先写简单写写后台的列表,同事说用MvcJqGrid,也得到了架构的同意. 可是不得不 ...

  2. JDBC向oracle插入数据

    public static void main(String[] args) throws SQLException { 2 3 4 String driver="oracle.jdbc.d ...

  3. 解决Redis Cluster模式下的排序问题

    通常的redis排序我们可以这么做: 比如按商品价格排序:sort goods_id_set by p_*_price 这样在非集群模式下是没问题的,但如果在集群模式下,就会报错: 说是在集群模式下不 ...

  4. iOS对textField进行字符长度限制的办法

    在项目开发过程中,遇到这么一个需求,编辑标签时,输入的最大长度需要限制为24个字节. 查阅了一些材料,并参考了之前项目的相关处理办法,今天在这里总结一下解决方案. 1.写一个截取字符串的方法,将超长的 ...

  5. javascript RegExp类型 学习小记

    在js里面,可以有两种方法来定义正则表达式,第一种是通过字变量的形式,第二种则是通过构造函数的形式: 1 字变量形式,格式是长这样子的 var expression = /pattern/flag p ...

  6. 393. UTF-8 Validation

    393. UTF-8 Validation 这个题很明确,刚开始我以为只能是一个utf,长度大于5的都判断为false,后来才明白题意. 有个小trick,就是长度大于1的时候,判断第一个数字开始1的 ...

  7. vbscript multiple line syntax

    Vbscript 如何将输出内容换行? ' VbCrLf represetns Carriage return–linefeed combination, for more information s ...

  8. 事件兼容IE

    addEvent:function(target, functionref, tasktype) { if (target.addEventListener) target.addEventListe ...

  9. GDI+ 如何将图片绘制成圆形的图片

    大概意思就是不生成新的图片,而是将图片转换为圆形图片. 实现代码如下: private Image CutEllipse(Image img, Rectangle rec, Size size) { ...

  10. memcached全面剖析--4

    memcached的分布式算法   memcached的分布式 正如第1次中介绍的那样, memcached虽然称为“分布式”缓存服务器,但服务器端并没有“分布式”功能. 服务器端仅包括 第2次. 第 ...