1、视图

 <LinearLayout 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:orientation="vertical"
tools:context=".MainActivity" > <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click1"
android:text="透明"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click2"
android:text="缩放"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click3"
android:text="旋转"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click4"
android:text="平移"
/> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="click5"
android:text="组合"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
>
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
/>
</LinearLayout> </LinearLayout>

2、android代码

 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.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){
//第一个参数表示开始透明度;0表示完全透明
//第二个参数表示结束透明度;1表示完全不透明
AlphaAnimation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(2000);//设置动画时间为2妙
animation.setRepeatCount(2);//设置重复次数,因此总共3次
animation.setRepeatMode(Animation.REVERSE);//设置重复模式
iv.startAnimation(animation);
} //缩放图片
public void click2(View view){
//第一个参数为开始x轴缩放坐标;第二个参数为结束时x轴缩放坐标
//第三个参数为开始y轴缩放坐标;第四个参数为结束时y轴缩放坐标
//第五个参数为中心x坐标以什么为参照,Animation.RELATIVE_TO_SELF说明以自己为参照;第六个参数为参照坐标比例;第七、八与第五、六相同,只不过它指的是y轴
ScaleAnimation animation = new ScaleAnimation(0.2f, 2.0f, 0.2f, 2.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(2000);
animation.setRepeatCount(2);
animation.setRepeatMode(Animation.REVERSE);
iv.startAnimation(animation);
} //旋转
public void click3(View view){
//第一参数,开始旋转角度
//第二个参数为旋转到多少度
//第3-6个参数与缩放的第5-8的参数相同
RotateAnimation animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(2000);
animation.setRepeatCount(2);
animation.setRepeatMode(Animation.REVERSE);
iv.startAnimation(animation);
} //平移
public void click4(View view){
//x轴
//第一个参数为参照类型:Animation.RELATIVE_TO_PARENT以父窗口为参照
//第二个参数为开始坐标比例
//第三个同第一个;第四个参数是说明要平移多长的比例;1.0说明要有父窗口的宽度 //y轴同上 TranslateAnimation animation = 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);
animation.setDuration(2000);
animation.setRepeatCount(2);
animation.setRepeatMode(Animation.REVERSE);
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);
} }

tweenanim动画的更多相关文章

  1. 【Android动画】之Tween动画 (渐变、缩放、位移、旋转)

    Android 平台提供了两类动画. 一类是Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转.平移.放缩和渐变). 第二类就是 Frame动画,即顺序的播放事先做好的图像,与g ...

  2. Android(java)学习笔记199:Android中补间动画(Tween Animation)

    本文主要简单介绍补间动画使用代码实现, 关于使用xml实现补间动画,可以参看:自定义控件三部曲之动画篇(一)——alpha.scale.translate.rotate.set的xml属性及用法 1. ...

  3. Android 动画系列

    Android种最常用的动画: ~1~Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转.平移.放缩和渐变) Tweene Animations 主要类: Animation   ...

  4. 以xml的方式实现动画

    1.java代码 package com.example.tweenanim; import android.os.Bundle; import android.app.Activity; impor ...

  5. 【转】android动画之Tween动画 (渐变、缩放、位移、旋转)

    原文:http://blog.csdn.net/feng88724/article/details/6318430 Android 平台提供了两类动画. 一类是Tween动画,就是对场景里的对象不断的 ...

  6. Android学习笔记_55_Tween动画 (渐变、缩放、位移、旋转)

    Android 平台提供了两类动画. 一类是Tween动画,就是对场景里的对象不断的进行图像变化来产生动画效果(旋转.平移.放缩和渐变).第二类就是 Frame动画,即顺序的播放事先做好的图像,与gi ...

  7. Android(java)学习笔记142:Android中补间动画(Tween Animation)

    本文主要简单介绍补间动画使用代码实现, 关于使用xml实现补间动画, 可以参看:自定义控件三部曲之动画篇(一)——alpha.scale.translate.rotate.set的xml属性及用法 1 ...

  8. 动画requestAnimationFrame

    前言 在研究canvas的2D pixi.js库的时候,其动画的刷新都用requestAnimationFrame替代了setTimeout 或 setInterval 但是jQuery中还是采用了s ...

  9. 梅须逊雪三分白,雪却输梅一段香——CSS动画与JavaScript动画

    CSS动画并不是绝对比JavaScript动画性能更优越,开源动画库Velocity.js等就展现了强劲的性能. 一.两者的主要区别 先开门见山的说说两者之间的区别. 1)CSS动画: 基于CSS的动 ...

随机推荐

  1. PHP自学之路-----javascript基础入门

    Javascript概述: Javascript是基于对象和事件的脚本语言.特点; 1.安全性(不允许直接访问本地硬盘),它可以做的就是信息的动态交互. 2.跨平台性. JavaScript与HTML ...

  2. .net平台是什么?.net平台的组成,.net平台的好处

    1..net(dotnet)平台是什么? .net平台是微软公司设计的一个用于开发各种应用的"框架"和程序的运行环境. 2..net平台的组成: a..net Framework( ...

  3. TextView实现多个TextView对象的走马灯效果

    1:自定义一个控件继承TextView,重写isFocused方法,返回值为true; package com.example.helloandroid; import android.R.bool; ...

  4. AIX LVM学习笔记

    LVM: LOGIC VOLUMN MANAGEMENT (逻辑卷管理器) 通过将数据在存储空间的 逻辑视图 与 实际的物理磁盘 之间进行映射,来控制磁盘资源.实现方式是在传统的物理设备驱动层之上加载 ...

  5. Linux下安装JRE

    (1)下载jre-7u5-linux-i586.tar.gz,上传至/root目录 (2)执行tar -zxf jre-7u5-linux-i586.tar.gz (3)mv jre1.7.0_05 ...

  6. OpenCV配置使用版

    在VS2010环境中应用Opencv,网上找到了很多配置方法,但大多都是老版本的,很多新手面对最新版本的Opencv无从下手,就给新手童鞋写了这么一篇超级详细的配置攻略,贴上来共享.要强调一点的就是, ...

  7. python命令行解析工具argparse模块【1】

    argpaser是python中很好用的一个命令行解析模块,使用它我们可以很方便的创建用户友好型命令行程序.而且argparse会自动生成帮助信息和错误信息. 一.示例 例如下面的例子,从命令行中获取 ...

  8. 基于百度地图api + AngularJS 的入门地图

    转载请注明地址:http://www.cnblogs.com/enzozo/p/4368081.html 简介: 此入门地图为简易的“广州大学城”公交寻路地图,采用很少量的AngularJS进行inp ...

  9. 织梦dedecms|图片模型内容页标签

    图片列表开始:{dede:productimagelist}图片列表结束:{/dede:productimagelist}图片显示:     [field:imgsrc/]图集缩略图:  {dede: ...

  10. hdu 4372 第一类stirling数的应用/。。。好题

    /** 大意: 给定一系列楼房,都在一条水平线上,高度从1到n,从左侧看能看到f个, 从右侧看,能看到b个,问有多少种这样的序列.. 思路: 因为肯定能看到最高的,,那我们先假定最高的楼房位置确定,那 ...