1、java代码

 package com.example.tweenanim;

 import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView; public class MainActivity extends Activity {
private ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv);
} //透明度
public void click1(View view){
Animation animation = AnimationUtils.loadAnimation(this,R.anim.alpha_anim);
iv.startAnimation(animation);
}
//缩放
public void click2(View view){
Animation animation = AnimationUtils.loadAnimation(this,R.anim.scale_anim);
iv.startAnimation(animation);
}
//旋转
public void click3(View view){
Animation animation = AnimationUtils.loadAnimation(this,R.anim.rotate_anim);
iv.startAnimation(animation);
}
//平移
public void click4(View view){
Animation animation = AnimationUtils.loadAnimation(this,R.anim.translate_anim);
iv.startAnimation(animation);
}
//组合
public void click5(View view){
AnimationSet set = new AnimationSet(false); TranslateAnimation ta = new TranslateAnimation(Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f, Animation.RELATIVE_TO_PARENT, 0.0f, Animation.RELATIVE_TO_PARENT, 1.0f);
ta.setDuration(2000);
ta.setRepeatCount(2);
ta.setRepeatMode(Animation.REVERSE); RotateAnimation ra = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
ra.setDuration(2000);
ra.setRepeatCount(2);
ra.setRepeatMode(Animation.REVERSE); ScaleAnimation sa = new ScaleAnimation(0.2f, 2.0f, 0.2f, 2.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
sa.setDuration(2000);
sa.setRepeatCount(2);
sa.setRepeatMode(Animation.REVERSE); set.addAnimation(ta);
set.addAnimation(ra);
set.addAnimation(sa);
iv.startAnimation(set);
} }

2、动画xml,需要在res目录下新建anim文件夹,然后把以下的xml文件放进去

1)透明度alpha_anim.xml文件

 <?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.5"
android:fillAfter="true"
android:duration="2000"
> </alpha>

2)缩放scale_anim.xml文件

 <?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0.2"
android:toXScale="2.0"
android:fromYScale="0.2"
android:toYScale="2.0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"
> </scale>

3)旋转rotate_anim.xml文件

 <?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2000"
> </rotate>

4)平移translate_anim.xml文件

 <?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="20%p"
android:toXDelta="100%p"
android:fromYDelta="20%p"
android:toYDelta="100%p"
android:duration="2000"
> </translate>

注意:%后面的p说明是相对于父窗口;如果没有p,则相对于它自己

以xml的方式实现动画的更多相关文章

  1. 21_Android中常见对话框,光传感器,通过重力感应器编写出指南针应用,帧动画,通过Jav代码的方式编写补间动画,通过XML的方式编写补间动画

     1 关于常见的对话框,主要有: 常见的对话框,单选对话框,多选对话框,进度条对话框(转圈类型的),带进度条的对话框. 案例结构: 完成如下结构的案例,将所有的案例都测试一下: 2 编写MainA ...

  2. 转-springAOP基于XML配置文件方式

    springAOP基于XML配置文件方式 时间 2014-03-28 20:11:12  CSDN博客 原文  http://blog.csdn.net/yantingmei/article/deta ...

  3. Android中的三种XML解析方式

    在Android中提供了三种解析XML的方式:SAX(Simple API XML),DOM(Document Objrect Model),以及Android推荐的Pull解析方式.下面就对三种解析 ...

  4. struts_20_对Action中所有方法、某一个方法进行输入校验(基于XML配置方式实现输入校验)

    第01步:导包 第02步:配置web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app ...

  5. struts2视频学习笔记 22-23(基于XML配置方式实现对action的所有方法及部分方法进行校验)

    课时22 基于XML配置方式实现对action的所有方法进行校验   使用基于XML配置方式实现输入校验时,Action也需要继承ActionSupport,并且提供校验文件,校验文件和action类 ...

  6. hibernate 联合主键生成机制(组合主键XML配置方式)

    hibernate 联合主键生成机制(组合主键XML配置方式)   如果数据库中用多个字段而不仅仅是一个字段作为主键,也就是联合主键,这个时候就可以使用hibernate提供的联合主键生成策略. 具体 ...

  7. web.xml中配置Spring中applicationContext.xml的方式

    2011-11-08 16:29 web.xml中配置Spring中applicationContext.xml的方式 使用web.xml方式加载Spring时,获取Spring applicatio ...

  8. 【Struts2学习笔记(11)】对action的输入校验和XML配置方式实现对action的全部方法进行输入校验

    在struts2中,我们能够实现对action的全部方法进行校验或者对action的指定方法进行校验. 对于输入校验struts2提供了两种实现方法: 1. 採用手工编写代码实现. 2. 基于XML配 ...

  9. Struts2第十篇【数据校验、代码方式、XML配置方式、错误信息返回样式】

    回顾以前的数据校验 使用一个FormBean对象来封装着web端来过来的数据 维护一个Map集合保存着错误信息-对各个字段进行逻辑判断 //表单提交过来的数据全都是String类型的,birthday ...

随机推荐

  1. c++复习(未完待续)

    1.使函数不能在定义该函数的文件之外访问的方法: (1)声明函数为static(2)将函数放到无名名字空间中 namespace { void g() { ......... } }

  2. 分析php获取客户端ip

    用php能获取客户端ip,这个大家都知道,代码如下: /** * 获取客户端ip * @param number $type * @return string */ function getClien ...

  3. Java之旅(一)---说说“异常”那些事

     从開始学习VB,就听说过"异常",认为异常处理就是加上try..catch,不让错误抛出给用户,到此为止,不要再往下问了,再问也不会了.这就是那时候的理解.如今随时项目经验的 ...

  4. Swift语言iOS开发:CALayer十则示例

    如你所知,我们在iOS应用中看到的都是视图(view),包括按钮视图.表视图.滑动条视图,还有可以容纳其他视图的父视图等. AD:[活动]Web和APP兼容性实战 Win10训练营免费报名 如你所知, ...

  5. SharePoint Secure Store Service(SSSS)的使用(一)

    SSS在案例中的应用: SSS介绍 SSS部署 SSS应用 http://www.cnblogs.com/renzh/archive/2013/03/31/2990280.html 创建.部署.应用S ...

  6. dict和set的使用

    使用dict和set dict Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. 举个例子 ...

  7. BZOJ 2190 仪仗队

           这道题的关键就是找到所有的点中,x与y互质的点,第一反应必定是暴搜,稍想一下可以从中分开求一半,但范围仍然限定了这条路行不通,仔细画了几张图后发现下图中从第三行起第k行可连fai k个, ...

  8. Yii2归档安装法

    打开dos 操作命令  1.先把init.bat  拖到dos命令窗口 打开 (如果拖过去没打开 可以回车Enter一下) 这里需要注意一下  下图红圈中是两种环境  0->开发环境  1-&g ...

  9. css基本框架

  10. XIV

    http://publib.boulder.ibm.com/infocenter/ibmxiv/r2/index.jsp