一、简介

二、代码
1.xml
(1)activity_main.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"> <Button android:id="@+id/scaleButtonId" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:text="测试scale动画效果" /> <Button android:id="@+id/rotateButtonId" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_above="@id/scaleButtonId"
android:text="测试rotate动画效果" /> <Button android:id="@+id/alphaButtonId" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_above="@id/rotateButtonId"
android:text="测试alpha动画效果" /> <Button android:id="@+id/translateButtonId"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_above="@id/alphaButtonId" android:text="测试translate动画效果" /> <LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:id="@+id/imageViewId"
android:layout_width="wrap_content" android:layout_height="100dp"
android:layout_centerInParent="true" android:layout_marginTop="100dip"
android:src="@drawable/android" />
</LinearLayout>
</RelativeLayout>

2.java
(1)MainActivity.java

 package com.animation1;

 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 { private ImageView imageView = null;
private Button rotateButton, scaleButton, alphaButton, translateButton = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); imageView = (ImageView) findViewById(R.id.imageViewId); rotateButton = (Button) findViewById(R.id.rotateButtonId);
scaleButton = (Button) findViewById(R.id.scaleButtonId);
alphaButton = (Button) findViewById(R.id.alphaButtonId);
translateButton = (Button) findViewById(R.id.translateButtonId); rotateButton.setOnClickListener(new RotateButtonListener());
scaleButton.setOnClickListener(new ScaleButtonListener());
alphaButton.setOnClickListener(new AlphaButtonListener());
translateButton.setOnClickListener(new TranslateButtonListener()); } private class RotateButtonListener implements OnClickListener {
@Override
public void onClick(View v) {
AnimationSet animationSet = new AnimationSet(true);
RotateAnimation rotateAnimation = new RotateAnimation(0, 360,
AnimationSet.RELATIVE_TO_PARENT, 1f,
Animation.RELATIVE_TO_PARENT, 0f);
rotateAnimation.setDuration(5000);
animationSet.addAnimation(rotateAnimation);
imageView.startAnimation(animationSet);
}
} private class ScaleButtonListener implements OnClickListener {
@Override
public void onClick(View v) {
AnimationSet animationSet = new AnimationSet(true);
ScaleAnimation scaleAnimation = new ScaleAnimation(1, 0.1f, 1, 0.1f,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animationSet.addAnimation(scaleAnimation);
animationSet.setStartOffset(1000);
animationSet.setFillAfter(true);
animationSet.setFillBefore(false);
animationSet.setDuration(2000);
imageView.startAnimation(animationSet);
}
} private class AlphaButtonListener implements OnClickListener {
@Override
public void onClick(View v) {
AnimationSet animationSet = new AnimationSet(true);
AlphaAnimation alphaAnimation = new AlphaAnimation(1, 0);
alphaAnimation.setDuration(1000);
animationSet.addAnimation(alphaAnimation);
imageView.startAnimation(animationSet);
}
} private class TranslateButtonListener implements OnClickListener {
@Override
public void onClick(View v) {
AnimationSet animationSet = new AnimationSet(true);
TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, 1.0f);
translateAnimation.setDuration(1000);
animationSet.addAnimation(translateAnimation);
imageView.startAnimation(translateAnimation);
}
}
}

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. json解析日期方法 问题的解决方案

    之前在做项目的时候发现,用json格式传输日期数据的时候,发现从数据库中传回到页面的数据出现错误,查阅相关资料才知道,原来json不支持日期解析,要自己解决,解决方案也很简单,写一段js代码就OK了- ...

  2. java多线程总结二:后台线程(守护线程)

    所谓的后台线程,是指在程序运行的时候在后台提供一种通用服务的线程,并且这种线程并不属于程序中不可或缺的部分.因此当所有的非后台线程结束时,程序也就终止了,同时会杀死所有后台线程.反过来说,只要有任何非 ...

  3. Android笔记之adb命令解析1

    要在cmd命令中直接使用adb,需要配置环境变量:目录XXX\sdk\platform-tools 查看adb -help 帮助命令打印出以下内容: Android Debug Bridge vers ...

  4. 修改placeholder颜色

    #contact_info为textarea的ID #contact_info::-webkit-input-placeholder{ color:#999;}#contact_info:-moz-p ...

  5. 牛客网算法题之All-in-All

    题目: 有两个字符串s 和t,如果即从s 中删除一些字符,将剩余的字符连接起来,即可获得t.则称t是s 的子序列.请你开发一个程序,判断t是否是s的子序列. 输入描述: 输入包含多组数据,每组数据包含 ...

  6. 第43条:返回零长度的数组或者集合,而不是null

    private final List<Cheese> cheesesInStock = ...; public Cheese[] getCheese() { if(cheesesInSto ...

  7. jQuery—一些常见方法(3)【width(),innerWidth(),outerWidth()】

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Oracle 关于定义约束 / 修改表结构 /修改约束

    ---约束分5种:主键 外键 唯一 非空 检查5类约束 Oracle中分列级别约束 与 表级别约束 列级别约束:在创建表时再列上面加约束 例如: create table table11( stuno ...

  9. [转]MonkeyRunner在Windows下的Eclipse开发环境搭建步骤(兼解决网上Jython配置出错的问题)

    MonkeyRunner在Windows下的Eclipse开发环境搭建步骤(兼解决网上Jython配置出错的问题)   网上有一篇shangdong_chu网友写的文章介绍如何在Eclipse上配置M ...

  10. 2014年度辛星html教程夏季版第六节

    不知道这样大家会不会感觉枯燥,总之不管大家怎么样,辛星始终会陪伴大家的,期待您的关注和支持,也衷心的希望我的博客能让您少走弯路,获得更系统的知识. ***************表格********* ...