一、简介

二、代码
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. }

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

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

    一.简介 二.代码1.res\anim下的xml(1)alpha.xml.xml <?xml version="1.0" encoding="utf-8" ...

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

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

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

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

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

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

  5. go微服务框架kratos学习笔记四(kratos warden-quickstart warden-direct方式client调用)

    目录 go微服务框架kratos学习笔记四(kratos warden-quickstart warden-direct方式client调用) warden direct demo-server gr ...

  6. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第一章:向量代数

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第一章:向量代数 学习目标: 学习如何使用几何学和数字描述 Vecto ...

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

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

  8. 20145330《Java学习笔记》第一章课后练习8知识总结以及IDEA初次尝试

    20145330<Java学习笔记>第一章课后练习8知识总结以及IDEA初次尝试 题目: 如果C:\workspace\Hello\src中有Main.java如下: package cc ...

  9. Android的Fragment的第一种声明方式

    Android的Frangment的第一种声明方式 实际效果图如下: 项目结构图如下: fragment1: package com.demo.fragementfirst; import andro ...

随机推荐

  1. 获取XML配置数据

    XML结构: <Setting>  <BIG>    <tdHead>      <td TdName="序号" TdWidth=&quo ...

  2. Java机试题目_怎样截取字符串

    面试题1  怎样截取字符串 考题题干 编写一个截取字符串的函数,输入为一个字符串和字节数,输出为按字节截取的字符串.但是要保证汉字不被截半个,如"我ABC"4,应该截为" ...

  3. ios Swift 资源池

    Swift入门教程: http://www.cocoachina.com/applenews/devnews/2014/0604/8661.html Swift视频教程: http://www.coc ...

  4. 数据库E-R模型,数据字典

    概述:实体-联系模型(简称E-R模型) 模型结构: E-R模型的构成成分是实体集.属性和联系集,其表示方法如下: (1) 实体集用矩形框表示,矩形框内写上实体名. (2) 实体的属性用椭圆框表示,框内 ...

  5. Java多线程间通信-解决安全问题、等待唤醒机制

    /*1.增加一个知识点一个类怎么在所有的类中,让其它类来共同修改它的数据呢?可以用单例设计模式可以用静态可以在其它类中做一个构造函数,接受同一个对象,这样就可以实现对象 2.状态选择可以用数字0 1 ...

  6. 如何从零开始实现一个soa远程调用服务基础组件

    说起soa远程调用基础组件,最著名的莫过于淘宝的dubbo了,目前很多的大型互联网公司都有一套自己的远程服务调用分布式框架,或者是使用开源的(例如dubbo),或者是自己基于某种协议(例如hessia ...

  7. 安卓热更新之Nuwa实现步骤

    安卓热更新之Nuwa实现步骤 最近热更新热修复的功能在安卓应用上越发火热,终于我的产品也提出了相应的需求. 经过两天的研究,搞定了这个功能,在这里还要多谢大神们的博客,大神们的原理分析很到位,不过对于 ...

  8. bat文件的妙用1-一键开启所有开发软件

    每天早上来的第一件事情,就是打开电脑,然后开一堆的软件 1.wamp 开发环境 2.钉钉   通讯工具 3.PHPstrom 开发工具 4.nodejs.bat Nodejs的扩展(node D:/w ...

  9. 使用jQuery.FileUpload和Backload自定义控制器上传多个文件

    当需要在控制器中处理除了文件的其他表单字段,执行控制器独有的业务逻辑......等等,这时候我们可以自定义控制器. 通过继承BackloadController □ 思路 BackloadContro ...

  10. 重新开始学习c#啦,希望能坚持下去!

    过了这么多年,还是感觉自己喜欢C#,喜欢编程,虽然自己什么技术也没有:做的项目也不算是项目: